题目

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1832

题意

n个数据,A,B两个玩家轮流从两端取1到多个数字,最终数字加和为分数,分数最大的获胜,A为先手,二者都很聪明,求A分数-B分数。

思路

如刘书,

区间DP,明显可以用a[i][j]记录区间[i,j)的先手最大分数。

感想

1. 要像刘一样,在能达到要求之后进一步思考如何减少时间

代码

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#define LOCAL_DEBUG
using namespace std;
typedef pair<int, int> MyPair;
const int MAXN = ;
int sum[MAXN][MAXN];
int a[MAXN][MAXN];
int mnleftA[MAXN][MAXN];
int mnrightA[MAXN][MAXN];
int g[MAXN]; int main() {
#ifdef LOCAL_DEBUG
freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\input.txt", "r", stdin);
//freopen("C:\\Users\\Iris\\source\\repos\\ACM\\ACM\\output.txt", "w", stdout);
#endif // LOCAL_DEBUG
int n;
for (int ti = ; scanf("%d", &n) == && n; ti++) {
for (int i = ; i < n; i++)scanf("%d", g + i);
for (int i = ; i < n; i++) {
sum[i][i] = ;
for (int j = i + ; j <= n; j++) {
sum[i][j] = sum[i][j - ] + g[j - ];
}
}
for (int len = ; len <= n; len++) {
for (int i = , j = i + len; j <= n; i++, j++) {
a[i][j] = sum[i][j] - min(mnleftA[i][j - ], mnrightA[i + ][j]);
mnleftA[i][j] = min(mnleftA[i][j - ], a[i][j]);
mnrightA[i][j] = min(mnrightA[i + ][j], a[i][j]); }
}
int ans = * a[][n] - sum[][n];
printf("%d\n", ans);
} return ;
}

UVa 10891 - Game of Sum 动态规划,博弈 难度: 0的更多相关文章

  1. UVa 10891 Game of Sum - 动态规划

    因为数的总和一定,所以用一个人得分越高,那么另一个人的得分越低. 用$dp[i][j]$表示从$[i, j]$开始游戏,先手能够取得的最高分. 转移通过枚举取的数的个数$k$来转移.因为你希望先手得分 ...

  2. 09_Sum游戏(UVa 10891 Game of Sum)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P67 例题28: 问题描述:有一个长度为n的整数序列,两个游戏者A和B轮流取数,A先取,每次可以从左端或者右端取一个或多个数,但不能两端 ...

  3. uva 10891 Game of Sum(区间dp)

    题目连接:10891 - Game of Sum 题目大意:有n个数字排成一条直线,然后有两个小伙伴来玩游戏, 每个小伙伴每次可以从两端(左或右)中的任意一端取走一个或若干个数(获得价值为取走数之和) ...

  4. [题解]UVa 10891 Game of Sum

    在游戏的任何时刻剩余的都是1 - n中的一个连续子序列.所以可以用dp[i][j]表示在第i个数到第j个数中取数,先手的玩家得到的最大的分值.因为两个人都很聪明,所以等于自己和自己下.基本上每次就都是 ...

  5. UVA 10891 Game of Sum

    题目大意就是有一个整数串,有两个人轮流取,每次可以取走一个前缀或后缀.两人都足够聪明,且都会使自己收益最大.求取完后先手比后手多多少. 每次我看见上面那句就会深感自己的愚笨无知. 所以来推推性质? 1 ...

  6. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  7. UVA - 10891 Game of Sum 区间DP

    题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19461 Game of sum Description This ...

  8. UVA 10891 Game of Sum(DP)

    This is a two player game. Initially there are n integer numbers in an array and players A and B get ...

  9. 28.uva 10891 Game of Sum 记忆化dp

    这题和上次的通化邀请赛的那题一样,而且还是简化版本... 那题的题解      请戳这里 ... #include<cstdio> #include<algorithm> #i ...

随机推荐

  1. Eclipse添加EGIT方法

    1. 安装EGIT, 其中一个方法: 2. 新建javaweb项目,测试git的使用. l  File > Team > Share Project 选择GIT 如何选择不了,则选择创建c ...

  2. VUE项目实现页面跳转

    打开一个VUE项目,目录结构是这样的: 如现在有两个页面aaa和HelloWorld,路由配置在index.js中: import Vue from 'vue' import Router from ...

  3. Debug记录(1)

    今天下午在给nRF52832写程序时,莫名遇到了这个错误 错误id是一个很奇怪的数. 原代码如下: static void timers_init(void) { uint32_t timer_err ...

  4. 梯度消失 / 梯度爆炸以及Xavier初始化

    2018-12-06 16:25:08 首先我们先来看一下求解梯度的公式,以下面三层的网络为例: 如果w初始化为大于1的数字,在深层神经网络计算梯度的时候就会出现梯度爆炸的现象: 如果w初始化为小于1 ...

  5. Twisted 简介

    Twisted是用Python实现的基于事件驱动的网络引擎框架,Twisted支持许多常见的传输及应用层协议,包括TCP.UDP.SSL/TLS.HTTP.IMAP.SSH.IRC以及FTP.就像Py ...

  6. English trip V1 - 23. Big and Bigger Teacher:Corrine Key: adjective comparisons 形容词 比较级

    In this lesson you will learn to make comparisons. 课上内容(Lesson) compare   n. 比较  vt. 比拟,喻为:[语]构成  vi ...

  7. OpenVPN参数详解

    一般选项: –config file : 从file中读取配置选项. –help : 显示选项. –version : 显示版权和版本信息. 隧道选项: –local host : 本地主机名或IP地 ...

  8. Asp.net博客系统收集和简单介绍

    国内Asp.net博客系统收集和简单介绍       [转载文章,仅供个人参考,引自http://www.soyaoo.com/Blog/post/92.html] 1.ZJ-Blog程序简介:基于A ...

  9. Digital Deletions HDU - 1404

    Digital deletions is a two-player game. The rule of the game is as following. Begin by writing down ...

  10. DFS CCPC2017 南宁I题

    The designers have come up with a new simple game called “Rake It In”. Two players, Alice and Bob, i ...