HDU 1087 Super Jumping! Jumping! Jumping!
来源:互联网 发布:ajaxupload.js 编辑:程序博客网 时间:2024/06/02 06:37
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.
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 24 1 2 3 44 3 3 2 10
4103
题意概括:找出最大的上升序列的和。
解题思路:先找出前两个数的最大上升序列的和,然后找出前三个,依次找完数组。每遇到一个新的数比较是否符合上升序列,如果符合,看这是第几个数,然后找出前n个数的上升序列和,加上新的数后是否大于这个序列和,大于则更新为新的序列和。
代码:
#include<stdio.h>#include<string.h>int max(int a,int b){if(a<b)a=b;return a;}int main(){int i,j,k,l,m,n,a[1100],f[1100];while(scanf("%d",&n),n){for(i=1;i<=n;i++){scanf("%d",&a[i]);}memset(f,0,sizeof(f));f[1]=a[1];for(i=2;i<=n;i++){for(j=1;j<i;j++){if(a[i]>a[j]){f[i]=max(f[i],a[i]+f[j]);}//for(k=1;k<=n;k++)//rintf("%d ",f[k]);//printf("\n");}f[i]=max(f[i],a[i]);}l=-1;for(i=1;i<=n;i++){if(f[i]>l)l=f[i];}printf("%d\n",l);}}样例
6
1 2 5 3 4 6
过程
1 3 0 0 0 0
1 3 6 0 0 0
1 3 8 0 0 0
1 3 8 4 0 0
1 3 8 6 0 0
1 3 8 6 0 0
1 3 8 6 5 0
1 3 8 6 7 0
1 3 8 6 7 0
1 3 8 6 10 0
1 3 8 6 10 7
1 3 8 6 10 9
1 3 8 6 10 14
1 3 8 6 10 14
1 3 8 6 10 16
16
阅读全文
0 0
- hdu/hdoj 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- Hdu 1087 - Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- Hdu 1087 Super Jumping! Jumping! Jumping!
- hdu - 1087 - Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- HDU 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping!
- hdu 1087 Super Jumping! Jumping! Jumping! DP
- pyspider安装配置
- tomcat开机自启动
- 如何获取网络视频(或者说后台返回视频URL)第一帧图片以及获取本地视频的第一帧图片
- 设计模式之装饰着模式
- UE4添加C++类 编译失败 解决办法
- HDU 1087 Super Jumping! Jumping! Jumping!
- Linux下gcc编译生成动态链接库*.so文件并调用它
- opencv 形态学处理——膨胀
- 给Java新手的一些建议----Java知识点归纳(Java基础部分)
- Codeforces 835E E. The penguin's game 交互题 多猪试毒
- Android软件开发之获取通讯录联系人信息
- Linux用户切换
- iOS中计算文件大小两种方法
- numpy的文件存储与处理