DP Problem C:Super Jumping! Jumping! Jumping!(HDU 1087)

2023-11-10 03:09
文章标签 dp problem hdu super 1087 jumping

本文主要是介绍DP Problem C:Super Jumping! Jumping! Jumping!(HDU 1087),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Problem C

Time Limit : 2000/1000ms (Java/Other)   Memory Limit :65536/32768K (Java/Other)

Total Submission(s) : 2   Accepted Submission(s) : 2

Problem Description

Nowadays, a kind of chess gamecalled “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you area good boy, and know little about this game, so I introduce it to younow.<br><br><center><imgsrc=/data/images/1087-1.jpg></center><br><br>The game canbe played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are markedby a positive integer or “start” or “end”. The player starts from start-pointand must jumps into end-point finally. In the course of jumping, the playerwill visit the chessmen in the path, but everyone must jumps from one chessmanto another absolutely bigger (you can assume start-point is a minimum andend-point is a maximum.). And all players cannot go backwards. One jumping cango from a chessman to next, also can go across many chessmen, and even you canstraightly get to end-point from start-point. Of course you get zero point inthis situation. A player is a winner if and only if he can get a bigger scoreaccording to his jumping solution. Note that your score comes from the sum ofvalue on the chessmen in you jumping path.<br>Your task is to output themaximum value according to the given chessmen list.<br>

 

 

Input

Input contains multiple testcases. Each test case is described in a line as follow:<br>N value_1value_2 …value_N <br>It is guarantied that N is not more than 1000 andall value_i are in the range of 32-int.<br>A test case starting with 0terminates the input and this test case is not to be processed.<br>

 

 

Output

For each case, print themaximum according to rules, and one line one case.<br>

 

 

Sample Input

3 1 3 2

4 1 2 3 4

4 3 3 2 1

0

 

 

Sample Output

4

10

3

算法分析:

跟求最长不下降子序列一个思路,只不过这里要求的是和最大不下降的子序列。

代码实现:

 

 

#include<bits/stdc++.h>
using namespace std;
int main()
{int n,i,j;while(~scanf("%d",&n)&&n){int num[1005],sum[1005],maxx;//sum[i]表示前i个不下降子序列的最大和memset(sum,0,sizeof(sum));for(i=1;i<=n;i++){scanf("%d",&num[i]);sum[i]=num[i];    //初始化,每一个至少包括它本身}for(i=1;i<=n;i++){maxx=-999999;for(j=1;j<=i-1;j++){if(num[j]<num[i]&&sum[j]>maxx)//找前面和最大的不下降子序列{maxx=sum[j];}}if(maxx>0)  //找到满足,sum[i]加上{sum[i]+=maxx;}}maxx=sum[1];for(i=2;i<=n;i++)if(sum[i]>maxx)maxx=sum[i];cout<<maxx<<endl;}return 0;
}

这篇关于DP Problem C:Super Jumping! Jumping! Jumping!(HDU 1087)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/380062

相关文章

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

hdu4826(三维DP)

这是一个百度之星的资格赛第四题 题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1004&cid=500 题意:从左上角的点到右上角的点,每个点只能走一遍,走的方向有三个:向上,向下,向右,求最大值。 咋一看像搜索题,先暴搜,TLE,然后剪枝,还是TLE.然后我就改方法,用DP来做,这题和普通dp相比,多个个向上

hdu1011(背包树形DP)

没有完全理解这题, m个人,攻打一个map,map的入口是1,在攻打某个结点之前要先攻打其他一个结点 dp[i][j]表示m个人攻打以第i个结点为根节点的子树得到的最优解 状态转移dp[i][ j ] = max(dp[i][j], dp[i][k]+dp[t][j-k]),其中t是i结点的子节点 代码如下: #include<iostream>#include<algorithm

hdu4865(概率DP)

题意:已知前一天和今天的天气概率,某天的天气概率和叶子的潮湿程度的概率,n天叶子的湿度,求n天最有可能的天气情况。 思路:概率DP,dp[i][j]表示第i天天气为j的概率,状态转移如下:dp[i][j] = max(dp[i][j, dp[i-1][k]*table2[k][j]*table1[j][col] )  代码如下: #include <stdio.h>#include

usaco 1.3 Mixing Milk (结构体排序 qsort) and hdu 2020(sort)

到了这题学会了结构体排序 于是回去修改了 1.2 milking cows 的算法~ 结构体排序核心: 1.结构体定义 struct Milk{int price;int milks;}milk[5000]; 2.自定义的比较函数,若返回值为正,qsort 函数判定a>b ;为负,a<b;为0,a==b; int milkcmp(const void *va,c

usaco 1.1 Broken Necklace(DP)

直接上代码 接触的第一道dp ps.大概的思路就是 先从左往右用一个数组在每个点记下蓝或黑的个数 再从右到左算一遍 最后取出最大的即可 核心语句在于: 如果 str[i] = 'r'  ,   rl[i]=rl[i-1]+1, bl[i]=0 如果 str[i] = 'b' ,  bl[i]=bl[i-1]+1, rl[i]=0 如果 str[i] = 'w',  bl[i]=b

poj 3974 and hdu 3068 最长回文串的O(n)解法(Manacher算法)

求一段字符串中的最长回文串。 因为数据量比较大,用原来的O(n^2)会爆。 小白上的O(n^2)解法代码:TLE啦~ #include<stdio.h>#include<string.h>const int Maxn = 1000000;char s[Maxn];int main(){char e[] = {"END"};while(scanf("%s", s) != EO

hdu 2093 考试排名(sscanf)

模拟题。 直接从教程里拉解析。 因为表格里的数据格式不统一。有时候有"()",有时候又没有。而它也不会给我们提示。 这种情况下,就只能它它们统一看作字符串来处理了。现在就请出我们的主角sscanf()! sscanf 语法: #include int sscanf( const char *buffer, const char *format, ... ); 函数sscanf()和

hdu 2602 and poj 3624(01背包)

01背包的模板题。 hdu2602代码: #include<stdio.h>#include<string.h>const int MaxN = 1001;int max(int a, int b){return a > b ? a : b;}int w[MaxN];int v[MaxN];int dp[MaxN];int main(){int T;int N, V;s

hdu 1754 I Hate It(线段树,单点更新,区间最值)

题意是求一个线段中的最大数。 线段树的模板题,试用了一下交大的模板。效率有点略低。 代码: #include <stdio.h>#include <string.h>#define TREE_SIZE (1 << (20))//const int TREE_SIZE = 200000 + 10;int max(int a, int b){return a > b ? a :