HDU 1087

简介: Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13479 Accepted ...

Super Jumping! Jumping! Jumping!

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


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
 1 //最大上升子序列和 
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int a[1001],b[1001];
 6 int num;
 7 
 8 int main()
 9 {
10     int i,j,k;
11     int ans,res;
12     while (cin>>num,num)
13     {
14         for (i=0;i<num;i++)
15         {
16             cin>>a[i];
17             b[i]=-1;
18         }
19         res=-1;
20         for (i=num-1;i>=0;i--)
21         {
22             ans=0;
23             for (j=i+1;j<num;j++)
24             {
25                 if(a[j]>a[i]&&b[j]>ans)
26                     ans=b[j];
27             }
28             b[i]=a[i]+ans;
29             res=res>b[i]?res:b[i];
30         }
31        cout<<res<<endl;
32     }
33     return 0;
34 }

 

View Code
 1 //因为不一定连续 下面的wa 
 2  #include <iostream>
 3  using namespace std;
 4  
 5  int a[1001];
 6  int num;
 7  
 8  int main()
 9  {
10      int i,j,k;
11      int ans,res;
12      while (cin>>num,num)
13      {
14          for (i=0;i<num;i++)
15          {
16              cin>>a[i];
17          }
18          res=-1;
19          for (i=0;i<num;i++)
20          {
21              ans = a[i];
22              for (j=i+1;j<num;j++)
23              {
24                  if(a[j]>a[])
25                      ans+=a[j];
26                else
27                     break;
28              }
29              res=res>ans?res:ans;
30          }
31         cout<<res<<endl;
32      }
33      return 0;
34  }
View Code
 1 const int N=1005;
 2 int a[N];
 3 int sum[N]; //sum(i)以a[i]结尾的数列的和 保存的最大值
 4 int main(){
 5    int t,n,i,x,k,m,j,v,Max,temp,end,start,flag;
 6    while(cin>>n&&n){
 7      //memset(sum,0,sizeof(sum));
 8      Max=-1000000000;
 9      for(i=1;i<=n;i++){
10         scanf("%d",&a[i]);
11         sum[i]=a[i]; // 初始化,以a[i]结尾的和,就一个为自己
12      }
13      for(i=1;i<=n;i++){
14       for(j=1;j<i;j++){
15         if(a[j]<a[i]&&sum[j]+a[i]>sum[i]) //a[j]在a[i]左边,且a[i]大,
16            sum[i]=sum[j]+a[i];
17       }
18      if(sum[i]>Max)  //记录最大值
19        Max=sum[i];
20    }
21    cout<<Max<<endl;
22    }
23   return 0;
24 }

 

目录
相关文章
|
10月前
|
Java 测试技术
HDU-1233-还是畅通工程
HDU-1233-还是畅通工程
48 0
|
Java 测试技术
hdu 1228 A + B
hdu 1228 A + B
66 0
HDU 2549 壮志难酬
壮志难酬 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 12541    Accepted Submission(s): 4166 Problem Description 话说MCA山上各路豪杰均出山抗敌,去年曾在江湖威名显赫的,江湖人称的甘露也不甘示弱,“天将降大任于斯人也,必先劳其筋骨,饿其体肤,空乏其身”他说。
1041 0
|
机器学习/深度学习
|
C++ Java
HDU1880
题意就是根据咒语查功能,根据功能查看是否存在相应咒语,题意简单,不过是道不错的练习题。         下面的都MLE了,听说C++用G++提交才可以AC,否则也MLE;方法很多,不想做了……         方法一:我用Java的HashMap一直MLE,即便由value反查key减少映射数也一样MLE,听说C++的map可以AC。
1095 0
hdu 4463 Outlets
点击打开链接hdu 4463 思路:最小生成树+kruskal 分析: 1 题目要求的找到n个商店组成n-1条边,并且要求耐克和苹果商店肯定要相连,求最短长度 2 很明显的最小生成树的模板题,由于要求耐克和苹果的商店要在一起那么就要把这两个商店编号合并到同一个集合,然后在利用kruskal计算。
917 0
hdu 1298 T9
点击打开链接hdu 1298 题意:题目说的是在那遥远的星球有一款叫诺基亚的手机,键盘采用题目的图的样式。给定n个单词的出现的概率,规定是相加的比如hell出现为4,hello概率为3则hell的概率为7。
767 0