题解 | #Redraiment的走法#
Redraiment的走法
https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa
//https://www.nowcoder.com/practice/24e6243b9f0446b081b1d6d32f2aa3aa?tpId=37&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26pageSize%3D50%26search%3D50%26tpId%3D37%26type%3D37&difficulty=&judgeStatus=&tags=&title=103&gioEnter=menu
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n = 0;
int maxn = 1;
while (cin >> n) {
int dp[n]; //使用变量定义容器长度,一定要等变量的值确定后
vector<int> height(n);
for (int i = 0; i < n; i++)
cin >> height[i];
for (int i = 0; i < n; i++) {
dp[i] = 1;
for (int j = 0; j < i; j++)
if (height[j] < height[i]){
dp[i] = max(dp[i], dp[j] + 1);
maxn = max(maxn, dp[i]);
}
}
cout << maxn << endl;
}
// for(const int &num:dp)
// cout << num;
}
查看9道真题和解析