博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDOJ_ACM_Super Jumping! Jumping! Jumping!
阅读量:5993 次
发布时间:2019-06-20

本文共 3005 字,大约阅读时间需要 10 分钟。

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 24 1 2 3 44 3 3 2 10
 
Sample Output
4103
 
Code
View Code
1 #include 
2 #define N 1000 3 int f[N + 5];//mark number and don't modify 4 int acc[N + 5];//accumulate the number and compare with each other 5 int main() 6 { 7 int i, j, n, max; 8 while (scanf("%d", &n) != EOF && n) 9 {10 //input11 for (i = 0; i < n; i++)12 {13 scanf("%d", &f[i]);14 acc[i] = f[i];15 }16 //find the longest substring17 max = f[0];18 for (i = 1; i < n; i++)19 {20 for (j = 0; j < i; j++)21 {22 if (f[j] < f[i] && acc[j] + f[i] > acc[i])23 {24 acc[i] = acc[j] + f[i];25 if (acc[i] > max)26 max = acc[i];27 }28 }29 }30 //print the result31 printf("%d\n", max);32 }33 return 0;34 }

Key points

After solved the before question about DP, I think this question is really a piece of cake.

Using one array to mark the inputed number, and using the another array to mark the accumulating number.

Each time comparing the sum of the present number and the previous accumulated number with the present accumulated number, you can confirm whether change the present accumulated number or not.

转载于:https://www.cnblogs.com/chuanlong/archive/2012/11/18/2775586.html

你可能感兴趣的文章
linxu select 返回值
查看>>
代码中特殊的注释技术——TODO、FIXME和XXX的用处
查看>>
Android开发(20)--RadioGroup的使用
查看>>
iphone开发之获取网卡的MAC地址和IP地址
查看>>
【网站国际化必备】Asp.Net MVC 集成Paypal(贝宝)快速结账 支付接口 ,附源码demo...
查看>>
java中不常见的keyword:strictfp,transient
查看>>
INDEX--创建索引和删除索引时的SCH_M锁
查看>>
linux C(hello world)
查看>>
微信平台BAE
查看>>
Java程序编译和运行的过程
查看>>
数学图形之牟合方盖
查看>>
Objective-C-类(static)方法、实例方法、overwrite(覆写)、属性(property)复习...
查看>>
PHP多次调用Mysql存储过程报错解决办法
查看>>
mysql的二级索引
查看>>
Cobar是提供关系型数据库(MySQL)分布式服务的中间件
查看>>
Oracle当前用户SQL
查看>>
JavaScript学习笔记之下拉选择框的操作
查看>>
ProgressDialog使用总结
查看>>
安装完操作系统后,必备开发软件安装
查看>>
网络爬虫基本原理(一)
查看>>