Super Jumping! Jumping! Jumping!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 17610 Accepted Submission(s): 7541
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.
题意:
跳棋每次都跳到大于该位置值的地方,对这些位置的值进行全部加和,输出最大和。
思路:
说白了就是求所有递增子序列和的最大值,首先必须要清楚,不是说子序列越长就是和越大,跟之前的最长递增子序列是不一样的。
对比最长递增子序列与最大和递增子序列:
最长递增子序列: 1.长度最长 2.递增
最大和递增子序列: 1.加和最大 2.递增
可以看出,同样的要求是递增序列。
设number[1.....N],与sum[1.....N],number表示该位置的值,sum代表每个位置最大和,设i与j两个位置,每次遍历都从 j =1开始到 i 位置结束,故 i 的范围是2到N,j 的范围是1到 i 。
那么sum[ i ]=number[ i ]+max { sum[1]......sum[i-1] },当然在max { sum[1]......sum[i-1] }这里面的所有项中,要满足条件number[ i ]>number[ j ],因为要求是递增序列。
与最长递增子序列对比:
length[ i ]=1+max { length[1]......length[i-1] },同样的,也许要number [ i ]>number [ j ]。
两者间的区别就是,最大和与本身的值有关,而最长序列与本身值无关,只需要长度+1,这一点在循环体中的写法有点不同。
AC:
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int n,i,j; int number[1005]; int sum[1005],max,max1; while(scanf("%d",&n)!=EOF) { if(n==0) break; memset(number,0,sizeof(number)); for(i=1;i<=n;i++) { scanf("%d",&number[i]); sum[i]=number[i]; } // printf("\n"); // for(i=1;i<=n;i++) // printf("%d ",number[i]); // printf("\n"); //记得初始化 max=1; for(i=2;i<=n;i++) { max1=0; //这个循环是为了找i前面的最大加和值用的 for(j=1;j<i;j++) { if(number[i]>number[j]) { if(sum[j]>max1) max1=sum[j]; } } //找到后就加上这个值成为符合条件下的自身最大加和值 sum[i]+=max1; //对比查找最大用的,直接写在同一个循环内,就不用再另外写一个来找里面的最大值输出了 if(sum[i]>max) max=sum[i]; // printf("\nmax1=%d\n",max1); // printf("sum[%d]=%d\n",i,sum[i]); // printf("max=%d\n",max); // system("pause"); //测试用 } printf("%d\n",max); } return 0; }
Compare:
最长递增子序列:
for(i=1;i<length;i++) { for(j=0;j<i;j++) if(s[i]>s[j]) max[i]=max[i]>max[j]+1?max[i]:max[j]+1; //直接对比更新值 if(max[i]>m) m=max[i]; }
最大和递增子序列:
for(i=2;i<=n;i++) { max1=0; for(j=1;j<i;j++) { if(number[i]>number[j]) { if(sum[j]>max1) max1=sum[j]; } } //这里不可以直接对比更新值,必须j循环完才可以 sum[i]+=max1; if(sum[i]>max) max=sum[i]; }
总结:
还是需要提高一下实现能力,不能急,得慢慢来……
相关推荐
1001 计算直线的交点数 1002 FatMouse's Speed1003 Common Subsequence1004 Max Sum 1005 Super Jumping! Jumping! Jumping! 1006 免费馅饼 1007 Humble Numbers1008 Monkey and Banana 1009 龟兔赛跑 1010 数塔
Jumping_into_c++
2-104兔子跳小游戏Blocky rabbit jumping 1.12-104兔子跳小游戏Blocky rabbit jumping 1.12-104兔子跳小游戏Blocky rabbit jumping 1.12-104兔子跳小游戏Blocky rabbit jumping 1.12-104兔子跳小游戏Blocky rabbit ...
Jumping Into C++高清文字版本. Want to learn to code? Want to learn C++? Struggling to follow your lecturer or books and tutorials written for experts? You're not alone. As a professional C++ developer...
Jumping into C++ 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
蹦极跳系统的仿真,整个蹦极跳系统的数学描述为mx =mg+bx-a1x -a2|x |x ,m为物体的重量,g为重力加速度,x为物体的位置。
Jumping_into_C++(with_sample_code)
Alex Allain - Jumping into C++ (with Sample Code) http://www.cprogramming.com/c++book/?inl=ft-nhp (this website alway be my online references for C/C++)
论坛大牛极力推荐的一本C++学习书籍,绝对值得下载
C++入门级教程。通俗易懂,讲解透彻。非常适合初学者。
[UVA11764] Jumping Mario
游戏一个游戏! 大概。
Simple Jumping Block Game in JavaScript Free Source Code
带有状态依赖时滞的马尔科夫跳基因调控网络的鲁棒稳定性,张文兵,方建安,这篇文章中,我们研究了带有状态依赖时滞和参数不确定马尔科夫跳基因调控网络的鲁棒稳定性问题,状态依赖时滞存在于翻译和调控过
Crazy City Car Roof Jumping疯狂城市汽车屋顶跳跃Unity汽车驾驶3d项目源码C# 支持Unity版本5.3.2f1及以上 描述 在不需要高速公路的幻想城市中驾驶您的赛车。当你的汽车在这个神秘的地形上跳跃时,从一个屋顶跳到另...
外研版一起小学英语六下《Module 5Unit 2 Some children are jumping in the water.》word教案.docx
Jumping_C 一个使用Node,Express,MOngoDB Atlas,P5JS的小型项目,用于复制带有隐藏的“ C”的“ 0”网格的流行Facebook病毒图像。在该项目中,“ C”将随机跳来跳去,从第三方API以添加更多挑战。 分数将被添加和...
蝗虫跳跃机理的分析,陈勇,,研究了黄胫小车蝗的形态结构。采用高速摄影技术,对黄胫小车蝗的跳跃特征进行了分析,得到了黄胫小车蝗的跳跃特征参数。利用虚拟
基于AMESim建模的液压弹跳机器人论文