[HDU] [1087] Super Jumping! Jumping! Jumping!

Problem Description

Loading...

Problem Analysis

A Dynamic Programming problem
I forced myself not to look at any editorial and just pushed through
and I guess I solved it

The idea is that for each point
you record the maximum value obtainable by ending at that point
then you just need to find the maximum among the values of all points
…I suppose this is what they call DP

Thinking about it, I’ve done a fair number of DP problems by now
I basically understand the idea behind DP
but I’m still not fluent, so more practice is necessary

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<stdio.h>
int n;
int a[1020],dp[1020];
int main() {
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);
	while(scanf("%d",&n),n) {
		int res=0;
		for(int i=1; i<=n; i++) {
			scanf("%d",&a[i]);
			dp[i]=a[i];
			if(dp[i]>res)
				res=dp[i];
		}
		for(int i=1; i<=n; i++) {
			for(int j=1; j<i; j++) {
				if(a[j]<a[i]&&dp[i]<dp[j]+a[i])
					dp[i]=dp[j]+a[i];
				if(dp[i]>res)
					res=dp[i];
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Problem address: 【HDU】[1087]Super Jumping! Jumping! Jumping!

Loading...