动态规划-3003-序列的最大上升子序列
来源:互联网 发布:淘宝网店实名认证照片 编辑:程序博客网 时间:2024/03/28 21:52
Problem C
Time Limit : 2000/1000ms (Java/Other) Memory Limit :65536/32768K (Java/Other)
Total Submission(s) : 17 Accepted Submission(s) : 3
Problem Description
Nowadays, a kindof chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU.Maybe you are a good boy, and know little about this game, so I introduce it toyou now.<br><br><center><img src=/data/images/1087-1.jpg></center><br><br>Thegame can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positiveinteger or “start” or “end”. The player starts from start-point and must jumpsinto end-point finally. In the course of jumping, the player will visit thechessmen in the path, but everyone must jumps from one chessman to anotherabsolutely bigger (you can assume start-point is a minimum and end-point is amaximum.). And all players cannot go backwards. One jumping can go from achessman to next, also can go across many chessmen, and even you can straightlyget to end-point from start-point. Of course you get zero point in thissituation. A player is a winner if and only if he can get a bigger scoreaccording to his jumping solution. Note that your score comes from the sum ofvalue on the chessmen in you jumping path.<br>Your task is to output themaximum value according to the given chessmen list.<br>
Input
Input containsmultiple test cases. Each test case is described in a line asfollow:<br>N value_1 value_2 …value_N <br>It is guarantied that Nis not more than 1000 and all value_i are in the range of 32-int.<br>Atest case starting with 0 terminates the input and this test case is not to beprocessed.<br>
Output
For each case,print the maximum according to rules, and one line one case.<br>
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
题意:求序列的最大上升子序列
思路:每个位置都有一个最大和,在此第n个位置的前面n-1个位置中选最接近a[n]且要小于a[n]的那个位置的最大和再加上a[n],就得到第n个位置的最大和,然后再找出所以位置中的最大和,就是所要的答案,小于an[j]的位置和sum[i]来算出本位置最大和 temp+an[i]。
代码:
#include<cstdio>
#include<cstring>
#define Maxn 10001
#include<cmath>
#include<algorithm>
using namespace std;
int n,an[1010];
int sum[1002];
int main(){
int i,j,temp,maxn;
while(scanf("%d",&n),n){
memset(sum,0,sizeof(sum));
memset(an,0,sizeof(an));
for(i=1;i<=n;i++)
scanf("%d",&an[i]);
maxn=-1;
for(i=1;i<=n;i++){
temp=0;
for(j=i-1;j>0;j--)
if(an[j]<an[i]&&temp<sum[j]) temp=sum[j];
sum[i]+=an[i]+temp;
maxn=max(maxn,sum[i]);
}
printf("%d\n",maxn);
}
return 0;
}
- 动态规划-3003-序列的最大上升子序列
- 动态规划:最大上升子序列
- 动态规划--最大上升子序列和
- 动态规划:最大上升子序列和
- 【动态规划】求最大上升子序列
- 上升子序列(动态规划
- poj 2533 【动态规划】【最大上升子序列】
- 题目1480:最大上升子序列和:动态规划
- hdu 1087 (最大上升子序列和)动态规划
- |NOIOJ|动态规划|3532:最大上升子序列和
- 动态规划练习一 13:最大上升子序列和
- 动态规划练习一 13:最大上升子序列和
- 动态规划练习题-13(最大上升子序列和)
- 动态规划练习一—13最大上升子序列
- ACM-动态规划13-最大上升子序列和
- 动态规划练习13:最大上升子序列和
- 动态规划练习--13(最大上升子序列和)
- 动态规划―最大上升子序列和
- SDUT 3344 数据结构实验之二叉树五:层序遍历
- 【贪心+优先队列】1428 活动安排问题【51nod】【难度:2级算法题】
- hdoj2029
- Hibernate_ManyToMany_Demo
- 编译模块时遇到Invalid module format
- 动态规划-3003-序列的最大上升子序列
- SourceInsight代码工程
- 统计学 入门基础概念篇 - Descriptive Statistics: Quantitative Measures(个人笔记)
- 环境变量的访问及设置
- SM2第二十一篇:OpenSSL中关于RSA_new和RSA_free的内存泄漏(CRYPTO_cleanup_all_ex_data)
- echo命令的-n、-e两个参数
- 【java并发】传统线程技术中创建线程的两种方式
- 数据结构实验之二叉树二:遍历二叉树
- assign weak retain strong copy关键字的区别