您的位置:首页 > 其它

hdu 1087 Super Jumping! Jumping! Jumping!-dp 最长上升子序列和

2015-04-26 22:05 453 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1087

 

水水DP!

 

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std;
int a[1010],dp[1010];

int main()
{
int n;
while(~scanf("%d",&n),n)
{
memset(a,0,sizeof(a));
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
for(int j=i-1;j>=0;j--)
{
if(a[i]>a[j])
dp[i]=max(dp[i],a[i]+dp[j]);
}
}
sort(dp+1,dp+1+n);
printf("%d\n",dp
);
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐