这道题是求上升序列的个数
代码:
#include<iostream>
using namespace std;
int max(int a, int b)
{
if (a < b)
{
return b;
}
return a;
}
int main()
{
int n = 0;
int a[1000], c[1000] = { 0 };
int max2 = 0;
while (cin >> n)
{
for (int i = 0; i < n; ++i)
{
cin >> a[i];
c[i] = 0;
max2 = 0;
}
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < i; ++j)
{
if (a[i] >= a[j])
{
c[i] = max(c[i], c[j] + 1);
}
}
max2 = max(max2, c[i]);
}
cout << max2 + 1 << endl;
}
return 0;
}