Run ID | 作者 | 问题 | 语言 | 测评结果 | Time | Memory | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
110675 | 汤奕硕 | 导弹拦截问题 | C++ | Wrong Answer | 0 MS | 276 KB | 844 | 2025-02-22 16:59:58 |
#include <iostream> #include <vector> using namespace std; int main() { vector<int> heights; int height; while (cin >> height) { heights.push_back(height); } int n = heights.size(); vector<int> dp(n, 1); // 初始化dp数组,每个元素至少为1 // 动态规划求解最长不增子序列 for (int i = 1; i < n; ++i) { for (int j = 0; j < i; ++j) { if (heights[j] >= heights[i]) { dp[i] = max(dp[i], dp[j] + 1); } } } // 找到最长不增子序列的长度 int maxLen = 0; for (int i = 0; i < n; ++i) { maxLen = max(maxLen, dp[i]); } // 计算最少需要的系统数 int minSystems = n - maxLen; // 输出结果 cout << minSystems << endl; return 0; }
------Input------
123 256 369 213 456 956 23 698 1236 321 500 666
------Answer-----
6
------Your output-----
9