DP专题训练之HDU 1087 Super Jumping!
生活随笔
收集整理的這篇文章主要介紹了
DP专题训练之HDU 1087 Super Jumping!
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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 0Sample Output
4 10 3求最大遞增序列和~(不要求連續。。)
看樣例我以為是求最大連續遞增序列和的說~~
//Asimple #include <iostream> #include <sstream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector> #include <cctype> #include <cstdlib> #include <stack> #include <cmath> #include <set> #include <map> #include <string> #include <queue> #include <limits.h> #include <time.h> #define INF 0xfffffff #define mod 1000000 #define swap(a,b,t) t = a, a = b, b = t #define CLS(a, v) memset(a, v, sizeof(a)) #define debug(a) cout << #a << " = " << a <<endl #define abs(x) x<0?-x:x #define srd(a) scanf("%d", &a) #define src(a) scanf("%c", &a) #define srs(a) scanf("%s", a) #define srdd(a,b) scanf("%d %d",&a, &b) #define srddd(a,b,c) scanf("%d %d %d",&a, &b, &c) #define prd(a) printf("%d\n", a) #define prdd(a,b) printf("%d %d\n",a, b) #define prs(a) printf("%s\n", a) #define prc(a) printf("%c", a) using namespace std; typedef long long ll; const int maxn = 1002; int n, m, num, T, k, len, ans, sum; int dp[maxn], a[maxn];//不一定連續~~~ void input() {while( ~srd(n) && n ) {for(int i=0; i<n; i++) {srd(a[i]);}CLS(dp, 0);dp[0] = a[0];for(int i=1; i<n; i++) {for(int j=0; j<i; j++) {if( a[i] > a[j])dp[i] = max(dp[i], dp[j]+a[i]);}dp[i] = max(dp[i], a[i]);}ans = 0;for(int i=0; i<n; i++) {ans = max(ans, dp[i]);}prd(ans);} }int main(){input();return 0; }
?
轉載于:https://www.cnblogs.com/Asimple/p/6232736.html
總結
以上是生活随笔為你收集整理的DP专题训练之HDU 1087 Super Jumping!的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: myrocks复制中断问题排查
- 下一篇: kafka rebalance 部分分