SDAU dp专题 1003
来源:互联网 发布:姜文 王朔 知乎 编辑:程序博客网 时间:2024/05/19 15:22
1:问题描述
Problem Description
Nowadays, a kind of 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 to you now.
The game 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 positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
Input contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
For each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
Sample Output
4
10
3
2:大致题意
求一个序列的递增子序列和的最大值。
3:思路
dp【i】代表的是以第i个元素结束的递增子序列的和的最大值。
每次遍历i的时候,遍历i前面的元素,求出比a【i】小的元素dp的最大值,赋值给dp【i】=max+a【i】;
4:感想
表达不清楚。啊啊啊啊啊。
5:ac代码
#include<iostream>#include<string.h>#include<set>#include<stdio.h>#include<vector>#include<algorithm>#include<numeric>#include<math.h>#include<string.h>#include<sstream>#include<stdio.h>#include<string>#include<cstdlib>#include<algorithm>#include<iostream>#include<map>#include<queue>#include<iomanip>#include<cstdio>using namespace std;int main(){ //freopen("r.txt","r",stdin); int a[10005]; int dp[10005]; int n,m,i,j,k,z,setp; while(cin>>n&&n!=0) { memset(dp,0,sizeof(dp)); for(i=1;i<=n;i++) { scanf("%d",&a[i]); } for(i=1;i<=n;i++) { setp=-32768; for(j=0;j<i;j++) { if(a[i]>a[j]) { setp=max(setp,dp[j]); } } dp[i]=setp+a[i]; //cout<<dp[i]<<endl; } int maxx=-32768; for(i=1;i<=n;i++) { if(dp[i]>maxx ) maxx=dp[i]; } cout<<maxx<<endl; } return 0;}
- SDAU dp专题 1003
- SDAU dp专题 1001
- SDAU dp专题 1002
- SDAU dp专题 1004
- SDAU dp专题 1005
- SDAU dp专题 1006
- SDAU dp专题 1007
- SDAU dp专题 1008
- SDAU dp专题 1009
- SDAU dp专题 1010
- SDAU dp专题 1011
- SDAU dp专题 1012
- SDAU dp专题 1013
- SDAU dp专题 1014
- 2016sdau课程练习专题二 1003
- 2016sdau课程练习专题三 1003
- 2016sdau课程练习专题四 1003
- SDAU 贪心专题 总结
- Leetcode #62. Unique Paths 路径搜寻 解题报告
- Android解惑 - 为什么要用Fragment.setArguments(Bundle bundle)来传递参数
- 面试之路(23)-递归和循环优缺点详解
- Hibernate多对多中间表有多个字段字段的注解配置方式(二)
- 简易计算器(逆波兰算法)
- SDAU dp专题 1003
- Hibernate多对多中间表有多个字段字段的注解配置方式(三)
- Android进程
- KMP模板
- Android ActionBar的基本用法
- 浅谈:自步学习(Self-Paced Learning)
- 202. Happy Number
- 23.Maven 项目介绍 - IntelliJ IDEA 使用教程
- MySQL常用命令