hdu 1087 super jumping! jumping! jumping!

经典DP题目,就是求最长上升子序列的和!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

#include <stdlib.h>
#include <string.h>
#define max(x,y) (x)>(y)?(x):(y)
__int64 max[1200];
__int64 a[1200];
int ()
{
int n,i,j;
__int64 temp;
while (scanf("%d",&n),n)
{
memset(max,0,sizeof(max));
for ( i = 0; i < n;i++)
{
scanf("%I64d",&a[i]);
temp = a[i];
for ( j = 0;j < i;j++)
if ( a[j] < a[i] )
temp = max(temp,max[j]+a[i]);
max[i] = temp;
}
temp = 0;
for ( j = 0; j < n; j++)
temp = max(max[j],temp);
printf("%I64dn",temp);
}
return 0;
}