最长下降子序列的水题,竟然初始化错了害我WA好几次,囧啊!
#include <stdio.h>
#include <string.h>
#define N 5005
int a[N], b[N];
int main()
{
int l = 0, cas = 0, ans;
while(scanf("%d", &a[l]), a[l] != -1)
{
if(cas) printf("\n");
l++;
while(scanf("%d", &a[l]), a[l] != -1)
{
l++;
}
memset(b, 0, sizeof(b));
ans = 0;
for(int i = 1; i < l; i++)
{
for(int j = 0; j < i; j++)
{
if(a[i] <= a[j] && b[i] <= b[j])
{
b[i] = b[j] + 1;
}
}
if(b[i] > ans) ans = b[i];
}
printf("Test #%d:\n", ++cas);
printf(" maximum possible interceptions: %d\n", ans + 1);
l = 0;
}
return 0;
}