#include <iostream>
using namespace std;
int main()
{
# define N 5
int arr[N] = {4,6,5,7,3};
const int n = sizeof(arr) / sizeof(int);
int dp[N] = {0};
for (int i = 0; i < n; i++) {
dp[i] = 1; // 默认长度是1,只有arr[i]自己
for (int j = 0; j < i; j++) {
if (arr[i] >= arr[j]) {
if (dp[j]+1 > dp[i]) {
dp[i] = dp[j] + 1;
}
}
}
}
for (int i = 0; i < N; i++) {
cout << dp[i] << " ";
}
cout << endl;
return 0;
}
最大不下降子序列
猜你喜欢
转载自blog.csdn.net/zxc120389574/article/details/105029387
今日推荐
周排行