hdu1087 动态规划

淡淡的烟草味﹌ 2022-08-03 05:14 290阅读 0赞

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 27470 Accepted Submission(s): 12188

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.

1087-1.jpg

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

  1. 3 1 3 2
  2. 4 1 2 3 4
  3. 4 3 3 2 1
  4. 0

Sample Output

  1. 4
  2. 10
  3. 3

Author

lcy

  1. #include<map>
  2. #include<vector>
  3. #include<cstdio>
  4. #include<iostream>
  5. #include<cstring>
  6. #include<string>
  7. #include<algorithm>
  8. #include<cmath>
  9. #include<stack>
  10. #include<queue>
  11. #include<set>
  12. #define inf 0x3f3f3f3f
  13. #define mem(a,x) memset(a,x,sizeof(a))
  14. using namespace std;
  15. typedef long long ll;
  16. typedef pair<int,int> pii;
  17. inline int in()
  18. {
  19. int res=0;char c;
  20. while((c=getchar())<'0' || c>'9');
  21. while(c>='0' && c<='9')res=res*10+c-'0',c=getchar();
  22. return res;
  23. }
  24. ll dp[1006];//dp[i]表示以a[i]结尾的最大值
  25. int a[1006];
  26. int main()
  27. {
  28. int n;
  29. while(~scanf("%d",&n) && n)
  30. {
  31. for(int i=1;i<=n;i++)a[i]=in();
  32. dp[1]=a[1];
  33. for(int i=2;i<=n;i++)
  34. {
  35. dp[i]=a[i];
  36. for(int j=1;j<i;j++)
  37. {
  38. if(a[j]<a[i])
  39. {
  40. dp[i]=max(dp[i],dp[j]+a[i]);
  41. }
  42. }
  43. }
  44. ll ans=-inf;
  45. for(int i=1;i<=n;i++)ans=max(ans,dp[i]);
  46. printf("%I64d\n",ans);
  47. }
  48. return 0;
  49. }

发表评论

表情:
评论列表 (有 0 条评论,290人围观)

还没有评论,来说两句吧...

相关阅读

    相关 HDU 1978(动态规划)

    问题描述 这是一个简单的生存游戏,你控制一个机器人从一个棋盘的起始点(1,1)走到棋盘的终点(n,m)。游戏的规则描述如下:  1.机器人一开始在棋盘的起始点并有起始点所

    相关 HDU 4540(动态规划)

    问题描述: 威威猫最近不务正业,每天沉迷于游戏“打地鼠”。    每当朋友们劝他别太着迷游戏,应该好好工作的时候,他总是说,我是威威猫,猫打老鼠就是我的工作!