博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)
阅读量:6173 次
发布时间:2019-06-21

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

Super Jumping! Jumping! Jumping!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 50078    Accepted Submission(s): 23221

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
 
 
 

题目大意:给出一个序列,求严格上升子序列的最大和。

看到题目,发现是之前做过的题目,但是读了题之后,发现不是普通的,(可能是状态不好,就不想做了)。dp[i] 表示 以 i 结尾的最大和。

状态转移方程:dp[i] = max(a[i], max{

dp[j] | 0 <= j < i, a[j] < a[i])} + a[i]

 

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define mem(a,b) memset((a),(b),sizeof(a))16 #define mp make_pair17 #define pb push_back18 #define fi first19 #define se second20 #define sz(x) (int)x.size()21 #define all(x) x.begin(),x.end()22 #define forn(i, x, n) for(int i = (x); i < n; i++)23 #define nfor(i, x, n) for(int i = n-1; i >= x; i--)24 typedef long long ll;25 const int inf = 0x3f3f3f3f;26 const ll INF =0x3f3f3f3f3f3f3f3f;27 const double pi = acos(-1.0);28 const double eps = 1e-5;29 const ll mod = 1e9+7;30 int a[1010], dp[1010]; 31 32 int main() {33 int n;34 while(~scanf("%d", &n), n) {35 forn(i, 0, n) {36 scanf("%d", &a[i]);37 }38 int ans;39 forn(i, 0, n) {40 ans = -inf;41 forn(j, 0, i) {42 if(a[j] < a[i])//找最大的dp[j] 43 ans = max(dp[j], ans);44 }45 dp[i] = max(a[i], ans + a[i]);//dp[i]46 }47 ans = -inf;48 forn(i, 0, n) {49 ans = max(ans, dp[i]);50 }51 printf("%d\n", ans);52 }53 }

 

 

复杂的AC代码(同时记录最长长度):

 

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define mem(a,b) memset((a),(b),sizeof(a))16 #define mp make_pair17 #define pb push_back18 #define fi first19 #define se second20 #define sz(x) (int)x.size()21 #define all(x) x.begin(),x.end()22 #define forn(i, x, n) for(int i = (x); i < n; i++)23 #define nfor(i, x, n) for(int i = n-1; i >= x; i--)24 typedef long long ll;25 const int inf = 0x3f3f3f3f;26 const ll INF =0x3f3f3f3f3f3f3f3f;27 const double pi = acos(-1.0);28 const double eps = 1e-5;29 const ll mod = 1e9+7;30 int a[1010], dp[1010], w[1010];31 32 int main() {33 int n;34 while(~scanf("%d", &n), n) {35 forn(i, 0, n) {36 scanf("%d", &a[i]);37 w[i] = a[i];38 }39 int maxx = -1;40 forn(i, 0, n) {41 dp[i] = 1;42 int temp = w[i];//因为下面会改变w[i] 的 值 43 forn(j, 0, i) {44 if(a[j] < a[i] && dp[j] + 1 > dp[i]) {45 dp[i] = dp[j] + 1;//dp存的是最长严格上升序列 46 if(temp + w[j] > w[i])47 w[i] = temp + w[j];//以i结尾的最大和 48 }49 }50 maxx = max(w[i], maxx);51 }52 printf("%d\n", maxx);53 }54 }

 

 

 

转载于:https://www.cnblogs.com/ACMerszl/p/9572933.html

你可能感兴趣的文章
批量删除oracle中以相同类型字母开头的表
查看>>
用tar和split将文件分包压缩
查看>>
大数据传输,文件传输的专业解决方案!
查看>>
常用URL地址
查看>>
struts国际化
查看>>
数据库 : 事物以及隔离性导致的问题
查看>>
Jquery乱码终极解决方案
查看>>
Android Fragment 真正的完全解析(上) (转载)
查看>>
多线程依次打印abcabc
查看>>
一:学习Linux前准备工作
查看>>
how to install wireless driver for Dell 630 in Ubuntu
查看>>
Kafka 配置参数汇总及相关说明
查看>>
弄清 CSS3 的 transition 和 animation
查看>>
服务器指定网卡进行备份数据避免影响业务口
查看>>
在Sublime Text 2下面开发Sass
查看>>
四则运算个人项目3
查看>>
eclipse 构建maven web工程
查看>>
237. Delete Node in a Linked List
查看>>
[转] webpack之plugin内部运行机制
查看>>
宽字节与多字节之间的转换
查看>>