题目连接:http://acm.pku.edu.cn/JudgeOnline/problem?id=1887
这个题就是一个求最长单调不升子序列的长度,用n^2的dp即可过!
#include <iostream>
using namespace std;
#define MAX 10000
short height[MAX];
unsigned short opt[MAX];
int t,i,j,m,len;
int main()
{
freopen("in.txt","r",stdin);
t = 1;
while(true)
{
len = 0;
while(cin >> height[len] && height[len] != -1)
++len;
if(len == 0)
break;
opt[0] = 1;
for(i = 1;i < len;++i)
{
m = 0;
for(j = 0;j < i;++j)
{
if(height[j] >= height[i] && opt[j] > m)
m = opt[j];
}
opt[i] = m + 1;
}
m = opt[0];
for(i = 1;i < len;++i)
{
if(opt[i] > m)
m = opt[i];
}
printf("Test #%d:/n",t);
printf(" maximum possible interceptions: %d/n/n",m);
++t;
}
return 0;
}