hihoCoder 1338 : A Game(dp)
2017-10-21 22:18
525 查看
A Game
Time limit:1000ms Memory limit:256MBProblem Description
Little Hi and Little Ho are playing a game. There is an integer array in front of them. They take turns (Little Ho goes first) to select a number from either the beginning or the end of the array. The number will be added to the selecter’s score and then be removed from the array.Given the array what is the maximum score Little Ho can get? Note that Little Hi is smart and he always uses the optimal strategy.
Input
The first line contains an integer N denoting the length of the array. (1 ≤ N ≤ 1000)The second line contains N integers A1, A2, … AN, denoting the array. (-1000 ≤ Ai ≤ 1000)
Output
Output the maximum score Little Ho can get.Sample Input
4 -1 0 100 2
Sample Output
99
题意:
每次轮到小Hi或者小Ho时,他们都面临同样的二选一决策:是拿走最左边的数,还是拿走最右边的数?问最后小Ho能拿到的最大点数是多少?
解题思路:
官方题解:《A Game》题目分析Code:
#include <cstdio> #include <iostream> using namespace std; const int maxn=1000+5; int a[maxn]; int sum[maxn]; int dp[maxn][maxn]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",a+i); sum[i]=sum[i-1]+a[i]; dp[i][i]=a[i]; } for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { dp[j][i+j]=sum[i+j]-sum[j-1]-min(dp[j+1][i+j],dp[j][i+j-1]); } } printf("%d\n",dp[1] ); return 0; }
相关文章推荐
- hihocoder A Game 区间dp
- hihocoder-#1338 : A Game
- hihocoder1199 Tower Defense Game(树形dp)
- hihocoder#1338 : A Game(dfs+DP)
- HiHoCoder_#1338 : A Game
- hihoCode #1338 : A Game (区间dp)
- [ZOJ3791] An Easy Game && 计数DP
- UVA 10891 Game of Sum(区间DP)
- zoj 3329 One Person Game 概率dp
- poj 1738 An old Stone Game(区间dp 合并石子问题直线型)
- 【DP&数组】Jump Game II
- [不平等博弈][DP] TCO 2017 Final Div1 Medium GameOfTokens
- zoj3329--One Person Game(概率dp第六弹:形成环的dp,带入系数,高斯消元)
- 10891 - Game of Sum(DP)
- hdu 5456 Matches Puzzle Game(dp)
- ZOJ-3329-One Person Game【7th浙江省赛】【概率dp】
- [DP] HDOJ 5456 Matches Puzzle Game
- [置顶] 201309_The First Game[DP专题]
- 【BZOJ2318】【spoj4060】game with probability Problem 概率DP
- POJ Strategic game(树形DP)