Super Jumping! Jumping! Jumping!
HDU - 1087题意:一种跳棋游戏, 起点和终点之间是一排标有正整数的石头, 每次只能跳到标记数字比当前位置大的石头上且只能向后跳,起点看作0, 终点看作无穷大, 得分是所有跳到的石头上数字之和;求最大得分;
本质就是求LIS;
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; int n; long long dp[1100]; long long a[1100]; int main(){ while(scanf("%d", &n), n){ memset(dp, 0, sizeof(dp)); for(int i=0; i<n; i++){ scanf("%lld", &a[i]); } long long ans=0; for(int i=0; i<n; i++){ long long temp=0; for(int j=0; j<i; j++){ if(a[i]>a[j]){ temp=max(temp, dp[j]); } } dp[i]=temp+a[i]; ans=max(dp[i], ans); } printf("%lld\n", ans); } return 0; }