kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)
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

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.
4 1 2 3 4
4 3 3 2 1
0
10
3
题目大意:给出一个序列,求严格上升子序列的最大和。
看到题目,发现是之前做过的题目,但是读了题之后,发现不是普通的,(可能是状态不好,就不想做了)。dp[i] 表示 以 i 结尾的最大和。
状态转移方程:dp[i] = max(a[i], max{dp[j] | 0 <= j < i, a[j] < a[i])} + a[i])
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define forn(i, x, n) for(int i = (x); i < n; i++)
#define nfor(i, x, n) for(int i = n-1; i >= x; i--)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
const ll mod = 1e9+;
int a[], dp[]; int main() {
int n;
while(~scanf("%d", &n), n) {
forn(i, , n) {
scanf("%d", &a[i]);
}
int ans;
forn(i, , n) {
ans = -inf;
forn(j, , i) {
if(a[j] < a[i])//找最大的dp[j]
ans = max(dp[j], ans);
}
dp[i] = max(a[i], ans + a[i]);//dp[i]
}
ans = -inf;
forn(i, , n) {
ans = max(ans, dp[i]);
}
printf("%d\n", ans);
}
}
复杂的AC代码(同时记录最长长度):
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
using namespace std;
#define mem(a,b) memset((a),(b),sizeof(a))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define forn(i, x, n) for(int i = (x); i < n; i++)
#define nfor(i, x, n) for(int i = n-1; i >= x; i--)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF =0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-;
const ll mod = 1e9+;
int a[], dp[], w[]; int main() {
int n;
while(~scanf("%d", &n), n) {
forn(i, , n) {
scanf("%d", &a[i]);
w[i] = a[i];
}
int maxx = -;
forn(i, , n) {
dp[i] = ;
int temp = w[i];//因为下面会改变w[i] 的 值
forn(j, , i) {
if(a[j] < a[i] && dp[j] + > dp[i]) {
dp[i] = dp[j] + ;//dp存的是最长严格上升序列
if(temp + w[j] > w[i])
w[i] = temp + w[j];//以i结尾的最大和
}
}
maxx = max(w[i], maxx);
}
printf("%d\n", maxx);
}
}
kuangbin专题十二 HDU1087 Super Jumping! Jumping! Jumping! (LIS)的更多相关文章
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)
Treats for the Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7949 Accepted: 42 ...
- kuangbin专题十二 POJ1661 Help Jimmy (dp)
Help Jimmy Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14214 Accepted: 4729 Descr ...
- kuangbin专题十二 HDU1176 免费馅饼 (dp)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- kuangbin专题十二 HDU1260 Tickets (dp)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)
Piggy-Bank Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- kuangbin专题十二 HDU1074 Doing Homework (状压dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- kuangbin专题十二 HDU1069 Monkey and Banana (dp)
Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- C Primer Plus学习笔记(三)- 字符串和格式化输入/输出
从一个简单的例子开始 #include <stdio.h> int main() { char name[10]; printf("Input Your Name:\n" ...
- PDM后续处理-驼峰规则、清除约束、外键改名
Option Explicit ValidationMode = True InteractiveMode = im_Batch Dim mdl '当前model '获取当前活 ...
- 如何解决SSH登录Solaris主机速度慢的问题
SSH登录速度慢可能有多种原因. 1. 与DNS有关 缺省情况下,当客户端用SSH登录solaris服务器时,服务器会试图反向解析客户端的IP 地址(即把IP地址解析成机器名).如果Solaris系统 ...
- Enable SVM while booted from alternate media (ZT)
http://www.seedsofgenius.net/uncategorized/solaris-tips-enable-svm-while-booted-from-alternate-media ...
- docker 笔记 (5)常用命令
images 显示镜像列表 history 显示镜像构建历史 commit 从容器创建新镜像 build 从 Dockerfile 构建镜像 tag 给镜像打 ta ...
- hadoop再次集群搭建(5)-CDH Install
登录 http://node1.com:7180/.用户名和密码都是admin.启动服务命令是 service cloudera-scm-server start 最开始两个页面直接conti ...
- jQuery-图片的放大镜显示效果(不需要大小图)
问题:当页面高度很大时,放大图片的图层不会跟随着 1.demo.html ;display:none;} #tip s {position:absolute;top:40px;l ...
- 卸载phonegap
npm uninstall cordova -gnpm uninstall phonegap -g
- HDU 4921 Map(状态压缩)
题意看这篇博客. 思路参考的这篇博客. 补充:面对这种问题有一个常见的套路.比如计算若干个区间对答案的贡献这种问题,直接暴力可能复杂度到O(n ^ 2), 而我们可以计算出每个元素在多少个合法区间中, ...
- php返回文件路径
1 basename — 返回路径中的文件名部分 如果文件名为test.php,路径为www/hj/test.php echo basename($_SERVER['PHP_SELF']); 输出为: ...