acgo题库
  • 首页
  • 题库
  • 题单
  • 竞赛
  • 讨论
  • 排行
  • 团队
  • 备赛专区

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
登录
注册
题目详情题解(0)讨论(0)提交记录(0)
  • tj

    #include <iostream> #include <vector> #include <algorithm> 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); vector<int> prev(n, -1); for (int i = 0; i < n; ++i) { for (int j = 0; j < i; ++j) { if (heights[j] >= heights[i] && dp[j] + 1 > dp[i]) { dp[i] = dp[j] + 1; prev[i] = j; } } } int maxLength = 0; int lastIndex = 0; for (int i = 0; i < n; ++i) { if (dp[i] > maxLength) { maxLength = dp[i]; lastIndex = i; } } vector<int> interceptedMissiles; while (lastIndex != -1) { interceptedMissiles.push_back(heights[lastIndex]); lastIndex = prev[lastIndex]; } reverse(interceptedMissiles.begin(), interceptedMissiles.end()); cout << maxLength << endl; for (int i = 0; i < interceptedMissiles.size(); ++i) { if (i != 0) { cout << " "; } cout << interceptedMissiles[i]; } cout << endl; return 0; }

    userId_undefined

    AAA秋褲批發lexora_哥

    小有名气题解仙人时空双修者秩序白银传道者
    3阅读
    0回复
    1点赞
首页