练习三 Problem C
2016-05-16 17:41
162 查看
题目:
[align=left]Problem Description[/align]
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.<br><br><center><img src=/data/images/1087-1.jpg></center><br><br>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.<br>Your task is to output the maximum value according to the given chessmen list.<br>
[align=left]Input[/align]
Input contains multiple test cases. Each test case is described in a line as follow:<br>N value_1 value_2 …value_N <br>It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.<br>A test case starting
with 0 terminates the input and this test case is not to be processed.<br>
[align=left]Output[/align]
For each case, print the maximum according to rules, and one line one case.<br>
[align=left]Sample Input[/align]
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
[align=left]Sample Output[/align]
4
10
3
题目大意:跳棋游戏,给出一些棋子,并赋予其特定的值,要求从最小的一个棋子跳到最大的一个棋子,中间可跳过一个或多个棋子。
解题思路:就是要求一个最大递增子段和,dp方程为dp[j]=max(dp[j],dp[i]+a[j]).
感想:经典dp题型的变形,dp[i]取决于dp[i-1]的最优解,不难做= =。
代码:
[align=left]Problem Description[/align]
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.<br><br><center><img src=/data/images/1087-1.jpg></center><br><br>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.<br>Your task is to output the maximum value according to the given chessmen list.<br>
[align=left]Input[/align]
Input contains multiple test cases. Each test case is described in a line as follow:<br>N value_1 value_2 …value_N <br>It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.<br>A test case starting
with 0 terminates the input and this test case is not to be processed.<br>
[align=left]Output[/align]
For each case, print the maximum according to rules, and one line one case.<br>
[align=left]Sample Input[/align]
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
[align=left]Sample Output[/align]
4
10
3
题目大意:跳棋游戏,给出一些棋子,并赋予其特定的值,要求从最小的一个棋子跳到最大的一个棋子,中间可跳过一个或多个棋子。
解题思路:就是要求一个最大递增子段和,dp方程为dp[j]=max(dp[j],dp[i]+a[j]).
感想:经典dp题型的变形,dp[i]取决于dp[i-1]的最优解,不难做= =。
代码:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm> using namespace std; int dp[1010],a[1010]; int max(int c,int d) { return c>d?c:d; } int main() { int Max,i,j,n; while(cin>>n&&n) { for(i=0;i<n;i++) { scanf("%d",&a[i]); dp[i]=a[i]; } Max=a[0]; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) { if(a[j]>a[i]) dp[j]=max(dp[j],dp[i]+a[j]); Max=max(Max,dp[j]); } printf("%d\n",Max); } return 0; }
相关文章推荐
- js回调函数
- 奋斗吧,程序员——第三十七章.雄关漫道真如铁,而今迈步从头越
- POJ 1276 Cash Machine 多重背包
- Jpgraph类库简介
- 分数的运算表达
- bootstrap--导航
- ES 分析器
- CodeForces 645F Cowslip Collections(gcd+欧拉函数)
- tomcat超时设置
- FlowControl: PauseFrame
- mysql自定义函数--得到字符串中最后一个分隔符前面的内容
- 五十三 网络编程 TCP/IP简介
- MYSQL存储过程
- JAVA第六次作业
- 常用Git指令简介
- LightOJ 1340 - Story of Tomisu Ghost (求n!在b进制下末尾0)
- awk实现统计单词和去重
- Jenkins -- 设置域账号登录错误导致无法登录
- [从头学数学] 第209节 带着计算机去高考(一)
- 一个关于try、catch、finally问题