题解 | #拦截导弹#最长递减子序列模板题,记住就行。
拦截导弹
https://www.nowcoder.com/practice/dad3aa23d74b4aaea0749042bba2358a
#include <iostream> using namespace std; int main() { int k; cin >> k; int nums[k]; for (int i = 0; i < k; i++) cin >> nums[i]; int dp[k]; int ans = 1; for (int i = 0; i < k; i++) { dp[i] = 1; for (int j = 0; j < i; j++) { if (nums[j] >= nums[i] && dp[j] + 1 > dp[i]) dp[i] = dp[j] + 1; } if (dp[i] > ans) ans = dp[i]; } cout << ans << endl; return 0; }