感觉跟dp没有什么关系,就只是贪心而已。
代码很简单,1A
#include <iostream>
#include <string.h>
using namespace std;
const int N = 10000000;
int dp[1000];
int len;
int max(int *dp)
{
int max = 0;
for(int i = 0; i < len; i ++)
{
if(max < dp[i])
max = dp[i];
}
return max;
}
int minIndex(int *dp, int a)
{
int min = 30000;
int index = 0;
for(int i = 0; i < len; i++)
{
if(dp[i] >= a && dp[i] <= min)
{
min = dp[i];
index = i;
}
}
return index;
}
int main()
{
int n;
while(cin >> n)
{
len = 0;
int *v = new int[N];
memset(v, 0, sizeof(v));
memset(dp, 0, sizeof(dp));
for(int i = 0; i < n; i++)
cin >> v[i];
for(int i = 0; i < n; i++)
{
if(v[i] > max(dp))
{
dp[len++] = v[i];
}
else
{
int a = v[i];
dp[minIndex(dp, a)] = a;
}
}
cout << len <<endl;
}
return 0;
}