HDU 1087--DP--(水)

题意:有一数轴,中间有n个具有不用权值的点可以走,每一步只能从权值低的跳到权值高的点,求从起点走到终点能收集到的最大的权值。

分析:基础的dp.  dp[i]代表走到i点时收集到的最大权值。状态转移方程:dp[i]=max(dp[j]+a[i],dp[i])  其中 j<i 且满足 value_j<value_i

代码:

#include<iostream>
using namespace std;
int n,a[1001];
long long dp[1001],mx;
long long DP()
{
	mx=-1;
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++){
			if(a[i]>a[j]&&dp[i]<dp[j]+a[i])
			   dp[i]=dp[j]+a[i];
		}
		if(mx<dp[i]) mx=dp[i];
	}
	return mx;
}
int main()
{
	while(cin>>n&&n){
		for(int i=0;i<n;i++) cin>>a[i];
		for(int i=0;i<n;i++) dp[i]=a[i];
		cout<<DP()<<endl;
	}
}
时间: 2024-10-26 18:08:33

HDU 1087--DP--(水)的相关文章

HDU 1069&amp;&amp;HDU 1087 (DP 最长序列之和)

H - Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Appoint description:  System Crawler  (2015-11-18) Description Nowadays, a kind of chess game called “Su

HDU 1087 DP

Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 25974    Accepted Submission(s): 11502 Problem Description Nowadays, a kind of chess game called "Super Jumping!

HDU 4960 (水dp)

Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi

HDU 1087 &amp;&amp; POJ 2533(DP,最长上升子序列).

~~~~ 两道题的意思差不多,HDU上是求最长上升子序列的和,而POJ上就的是其长度. 貌似还有用二分写的nlogn的算法,不过这俩题n^2就可以过嘛.. ~~~~ 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1087 http://poj.org/problem?id=2533 ~~~~ HDU1087: #include<cstdio> #include<cstring> #include<algorithm> #

hdu 1087 简单dp

思路和2391一样的.. <span style="font-size:24px;">#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; const int inf=(0x7f7f7f7f); int main() { int a; int s[10005]; int w[10005];

HDU 1520 Anniversary party 树DP水题

非常水的树DP,状态为当前为i,上级来没来 然后跑一遍记忆化搜索即可 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib>

[2016-03-27][HDU][1087][Super Jumping! Jumping! Jumping!]

时间:2016-03-27 15:51:40 星期日 题目编号:[2016-03-27][HDU][1087][Super Jumping! Jumping! Jumping!] 分析:dp[i]表示跳到第i个位置,能拿到的最多分,则dp[i] = max(dp[i] , dp[j] + v[i]) 能从j跳到i 遇到的问题:排序之和,a[1].v <= a[2].v 而不是 a[1].v < a[2].v 所以还是需要判断一下价值 #include <algorithm> #in

HDU 1087

一个简单而经典的dp; 若数组a:1 3 2 4 则数组b:1 4 3 8 b[i]每一个都要向前找 合法 的最大b[x]值加上当前的a[i]; 如b[2]=b[0]+a[2]; #include <iostream>using namespace std;int a[1001];int b[1001];int max_b(int i){    int max1=0;    for(int j=0;j<i;j++){        if(b[j]>max1&&a[i

(最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087

http://acm.hdu.edu.cn/showproblem.php?pid=1087 Super Jumping! Jumping! Jumping! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Description Nowadays, a kind of chess game called “Super Jump

E - Super Jumping! Jumping! Jumping! HDU 1087 (基础动态规划)

E - Super Jumping! Jumping! Jumping! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1087 Description Nowadays, a kind of chess game called "Super Jumping! Jumping! Jumping!" is very popular in