Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 15405 Accepted Submission(s): 6534
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.
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.
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
4 10 3
比较简单的题目但费了九牛二虎之力!
实质:最大递增子段和,状态方程:sum[j]=max{sum[i]}+a[j]; 其中,0<=i<=j,a[i]<a[j]
看来c语言基础没学好,,悲剧了。。。
当i==1时
不会执行j的for循环;因为j
不满足j>=1!!!!!!!!!
ac代码:
#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include <math.h> using namespace std; int num[1010]; int sum[1010]; int main() { int n; while(scanf("%d",&n)==1) { if(n==0) break; for(int i = 1;i<=n;++i) scanf("%d",&num[i]); int maxn = -1; memset(sum,0,sizeof(sum)); num[0] = 0; for(int i = 1;i<=n;++i) { int maxn1 = -1; for(int j = i-1;j>=1;--j) { if(num[j]<num[i]) { maxn1 = max(maxn1,sum[j]); } } sum[i] += maxn1 + num[i]; maxn = max(maxn,sum[i]); } printf("%d\n",maxn+1); } return 0; }
看来c语言基础没学好,,悲剧了。。。
当i==1时
不会执行j的for循环;因为j
不满足j>=1!!!!!!!!!
ac了:
#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include <math.h> using namespace std; int num[1010]; int sum[1010]; int main() { int n; while(scanf("%d",&n)==1) { if(n==0) break; for(int i = 1;i<=n;++i) scanf("%d",&num[i]); int maxn = 0; memset(sum,0,sizeof(sum)); num[0] = 0; for(int i = 1;i<=n;++i) { int temp = 0; for(int j = i-1;j>=1;--j) { if(num[j]<num[i]) { temp = max(temp,sum[j]); } } sum[i] += temp + num[i]; maxn = max(maxn,sum[i]); } printf("%d\n",maxn); } return 0; }
暴力求解出错。。看半天没发现错误。。。。求解??
#include<stdio.h> #include<string.h> #include<algorithm> #include<vector> #include <math.h> using namespace std; int num[1010]; int sum[1010]; int main() { int n; while(scanf("%d",&n)==1) { if(n==0) break; for(int i = 1;i<=n;++i) { scanf("%d",&num[i]); sum[i] = num[i]; } int maxn = -1; for(int i = 1;i<=n-1;++i) { int temp = i; for(int j = temp+1;j<=n;++j) if(num[j]>num[temp]) { sum[i] = sum[i]+num[j]; temp = j; } maxn = max(maxn,sum[i]); } maxn = max(maxn,num[n]); printf("%d\n",maxn); } return 0; }