您的位置:首页 > 其它

hdu1087

2015-12-30 16:34 232 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1087

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string.h>
using namespace std;
const int MAXN=1005;
const int INF=1e8;
int dp[MAXN],d[MAXN];
int main()
{
int n,ans;
while(cin>>n)
{
if(n==0)
break;
memset(dp,0,sizeof(dp));
d[0]=0;
for(int i=1;i<=n;i++)
scanf("%d",&d[i]);
for(int i=1;i<=n;i++)
{
ans=0;
///遍历,加上比当前小且dp最大的dp值
for(int j=0;j<i;j++)
{
if(d[i]>d[j])
{
ans=max(ans,dp[j]);
}
}
dp[i]=ans+d[i];
}
ans=-INF;
///寻找dp最大值
for(int i=1;i<=n;i++)
ans=max(dp[i],ans);
printf("%d\n",ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: