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;
}
#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;
}
相关文章推荐
- 数据结构 JAVA描述(六) 图的创建 (邻接矩阵+邻接表)
- WEB程序员需要掌握的十大MySQL优化技巧
- 递归下降语法分析程序设计
- 061 - Rotate List
- Style Scope Agile Edition―免费版商业智能产品
- postgresql学习line
- 解决android sdk无法访问Google的问题
- eclipse重新设置workspace路径
- JavaScriptCore在实际项目中的使用的坑
- AOP(2)
- iOS9 搜索API
- how to write one native program based on android source build system
- KVC设置unfinderKey和与系统关键字相同key的解决
- Linux下安装Tomcat7
- iOS通过dSYM文件分析crash
- cocostudio1.6UI编辑器中动画使用 cocos2dx3.3 播放问题记录
- 禁用其他应用程序, 代码块
- 转载For语句讲解
- 哈尔小波变换的原理及其实现(Haar)
- shader学习笔记二