1 #include2 #include 3 #include 4 5 using namespace std; 6 7 int list[26]; // 按袭击事件顺序保存各导弹高度 8 int dp[26]; // dp[i] 保存以第i个导弹结尾的最长不增子序列长度 9 10 11 int main() 12 {13 int n;14 while(cin >> n)15 {16 for(int i = 1; i <= n; ++i) 17 cin >> list[i];18 19 for(int i = 1; i <= n; ++i) // 按照袭击时间顺序确定每一个dp[i]20 {21 int tmax = 1; // 最大值的初始值为1,即以其结尾的最长不增子序列长度至少为122 for(int j = 1; j < i; ++j) // 遍历其前所有导弹高度23 if(list[j] >= list[i]) // 若j号导弹不比当前导弹低24 tmax = max(tmax, dp[j] + 1); // 将当前导弹排列在以j号导弹结尾的最长不增子序列之后,计算其长度dp[j] + 1, 若大于当前最大值,则更新最大值25 26 dp[i] = tmax; // 将dp[i] 保存为最大值27 }28 int ans = 1;29 for(int i = 1; i <= n; ++i)30 {31 ans = max(ans, dp[i]); // 找到以每一个元素结尾的最长不增子序列中的最大值, 该最大值即为答案32 } 33 cout << ans << endl;34 35 }36 37 return 0;38 }