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])

 #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)的更多相关文章

  1. kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)

    FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  2. kuangbin专题十二 POJ3186 Treats for the Cows (区间dp)

    Treats for the Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7949   Accepted: 42 ...

  3. kuangbin专题十二 POJ1661 Help Jimmy (dp)

    Help Jimmy Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14214   Accepted: 4729 Descr ...

  4. kuangbin专题十二 HDU1176 免费馅饼 (dp)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. kuangbin专题十二 HDU1029 Ignatius and the Princess IV (水题)

    Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K ( ...

  6. kuangbin专题十二 HDU1260 Tickets (dp)

    Tickets Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  7. kuangbin专题十二 HDU1114 Piggy-Bank (完全背包)

    Piggy-Bank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. kuangbin专题十二 HDU1069 Monkey and Banana (dp)

    Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

随机推荐

  1. 通过phpMyAdmin拿webshell

    general_log默认为关闭的,root权限开启后,general_log_file会保存所有的查询语句 所以可以开启general_log,然后设置general_log_file为一个php文 ...

  2. Windows条件变量

    详细见MSDN:http://msdn.microsoft.com/en-us/library/windows/desktop/ms686903%28v=vs.85%29.aspx 我们已经看到,当想 ...

  3. Mybatis 内置 Java 类型别名与 typeHandlers

    aliases There are many built-in type aliases for common Java types. They are all case insensitive, n ...

  4. 11-03SQLserver基础--子查询语句

    一.子查询--查询的嵌套(重点记忆) select MAX(age)from haha where bumen='销售部' --汇总-- select MAX(age)from haha where  ...

  5. 用命令查看端口占用情况 netstat -ano

    查看所有端口 netstat -ano 可以看到进程ID 参考某个具体端口,第五列就是PID进程ID了. netstat -aon|findstr "80"

  6. 多媒体基础知识之YUV数据

    1.什么是YUV格式 YUV,是一种颜色编码方法.Y表示明亮度(Luminance.Luma),也就是灰度值.U和V则是色度.浓度(Chrominance.Chroma),作用是描述影像色彩及饱和度, ...

  7. DAY16-Django之MTV

    MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Template(模版):负责如何把页面展示给用户 View(视图):负责业务逻辑,并在适当的时候 ...

  8. java在Win7 64位 获取客户端的IP,MAC,计算机名

    package com.javaweb.util; import java.io.IOException; import java.io.InputStreamReader; import java. ...

  9. ubuntu16搭建docker私库

    测试环境如下: 一.docker的安装 安装方法请查看这里的 安装教程 二.设置普通用户 1. centos的设置方法 $ sudo gpasswd -a docker ${USER} 2. ubun ...

  10. ztree 树的模糊搜索

    (转载),有个坑记录下: (原文)实现类似下面这种: /** * 展开树 * @param treeId */ function expand_ztree(treeId) { var treeObj ...