hihoCoder 1338 : A Game(dp)
来源:互联网 发布:程小青 知乎 编辑:程序博客网 时间:2024/05/16 06:17
A Game
Problem 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][n]); return 0;}
- hihoCoder 1338 : A Game(dp)
- hihocoder#1338 : A Game(dfs+DP)
- hihocoder A Game 区间dp
- hihocoder-#1338 : A Game
- hihocoder #1338 A Game
- hihoCoder太阁最新面经算法竞赛8 A Game(区间DP)
- hihoCode #1338 : A Game (区间dp)
- hihoCoder 1259 A Math Problem(数位dp)
- hihocoder#1241 : Best Route in a Grid(DP)
- P2734 游戏 A Game(DP问题)
- 2017 ICPC 北京站 H (hihocoder 1634) Puzzle Game (dp 最大子矩阵和)
- hihoCoder 1259 A Math Problem 数位dp
- hihoCoder 1259 A Math Problem 数位dp
- usaco A Game Java dp
- USACO--3.3A Game+dp
- A. Flipping Game DP水题
- UVALive 6919 A game for kids(树形dp)
- USACO-Section 3.3 A Game (区间DP)
- dlib——机器学习工具箱
- 数据结构—顺序表的实现
- leetcode#104:Maximum Depth of Binary Tree
- 面试准备—数据结构
- LeetCode刷题(18)
- hihoCoder 1338 : A Game(dp)
- 关于Igh-EthercatMaster DC时钟的同步方式和性能
- windows10+GPU下caffe数据集Lmdb格式制作+训练自己数据集
- 打印当前时间
- java语言基础(101)——反射
- python中使用pip install 命令时报ssl缺失的错误
- 周志华机器学习读后总结 第一章
- 一些感悟
- [ccf/csp题]201709-2公共钥匙盒