您的位置:首页 > 其它

HDU 1087 Super Jumping! Jumping! Jumping!

2014-07-24 13:47 295 查看
题目http://acm.hdu.edu.cn/showproblem.php?pid=1087

即求最大上升序列,典型DP

DP[I] = DATA[ I ]

DP[i] = Data[i] + max(DP[j] | 0<j<i 且Data[i]>Data[j] )

测试数据:

10 154 5 41 545 485 44 4 545 54 5444

正确集合:154 + 485 + 545 + 5444 = 6628

#include<stdio.h>
#include<string.h>
int dp[1002],a[1002];
int max(int a,int b)
{
return a > b ? a: b;
}
int main()
{
int i,j,n,temp;
//	freopen("a.txt","r",stdin);
while(~scanf("%d",&n),n)
{
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
dp[i] = 0;
}
dp[0] = 0;
for(i=1;i<=n;i++)
{
temp = 	dp[i] = 0;
for(j=0;j<i;j++)
{
if(a[i]>a[j] && temp<dp[j]+a[i])
{
temp = dp[j]+a[i];
}
}
dp[i] = temp;
}
temp = 0;
for(i=1;i<=n;i++)
temp = max(temp,dp[i]);
printf("%d\n",temp);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: