题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
//看到这道题第一想法就是求最长递增子序列, 我觉得挺简单的,但是耗时长,击败的对手少的可怜,写代码真是太难了 #include <iostream> #include <vector> using namespace std; //实质就是求最长递增子序列 int main(){ int n, data, max = 0; vector<int>numList; cin >> n; for (int i = 0; i < n; i++) { cin >> data; numList.push_back(data); } vector<int> v(numList.size(), 1); for (int i = 0; i < numList.size(); i++) { for (int j = i + 1; j < numList.size(); j++) { if (numList[j] > numList[i] && v[i] + 1 > v[j]) { v[j] = v[i] + 1; if (v[j] > max) max = v[j]; } } } cout << max << endl; }