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 ...
随机推荐
- 第十六章 Velocity工作原理解析(待续)
Velocity总体架构 JJTree渲染过程解析 事件处理机制 常用优化技巧 与JSP比较 设计模式解析之合成模式 设计模式解析之解释器模式
- nginx注册成服务
http://blog.csdn.net/t37240/article/details/51727563
- linux命令-mke2fs
想在磁盘下写东西,必须要先格式化 /////////////////////////////////////////////////////////////////////////////////// ...
- 工作的时候用到spring返回xml view查到此文章亲测可用
spring mvc就是好,特别是rest风格的话,一个 org.springframework.web.servlet.view.ContentNegotiatingViewResolver就可以根 ...
- sql server导入excel等数据
1.首先打开并登陆sql server数据库 2.选择要将表导入的数据库,右击选择任务-->导入数据 3.在弹出的窗口中选择下一步 4.在弹出的窗口中选择数据源,也就是从哪种文件导入,sql s ...
- c++对象模型探索(一)
粗略阅读了<深度探索c++对象模型>一书后,对c++对象底层的内存布局有了一些了解,但同时,也产生了一些疑惑: 1.将子类指针用dynamic_cast转成父类指针之后,其虚表指针会相应变 ...
- [patl2-020]功夫传人
解题关键:dfs的简单应用,需要注意类型double与int #include<cstdio> #include<cstring> #include<algorithm& ...
- 关于jdk1.5之后的自定拆装箱
我们都知道jdk在1.5版本之后,增加了一些新特性,我们称之为语法糖,有:1.泛型,2.foreach增强for循环,3.自动拆装箱,4.可变参数,5.枚举,6.静态导入 public class T ...
- IO流对文件的读取操作
/*1. 在当前项目的根目录下有一个名为“info.txt”的文件,里面存放的内容如下(可手动创建录入,不需要使用IO流): 2. 利用IO流的知识读取info.txt文件的内容, 在控制台上打印大写 ...
- windows 7 系统装机优化
A:系统设置 1.控制面板\系统和安全\Windows Update\更改设置 把系统升级以及提示关闭 控制面板\系统和安全\Windows 防火墙\自定义设置 把专用网络和公共网络的防火 ...