1031 - Easy Game(博弈dp)

【Elasticsearch专栏 16】深入探索:Elasticsearch的Master选举机制及其影响因素分析 Elasticsearch的Master选举机制是其分布式架构的基石,确保集群高可用性和数据一致性。通过多数派协议,节点间交换信息并投票选举Master,以维护集群状态和处理请求。该机制自动处理故障转移,保障服务连续性。 阅读详情

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or right end of the array but cannot take from both ends at a time. He can take as many consecutive numbers as he wants during his time. The game ends when all numbers are taken from the array by the players. The point of each player is calculated by the summation of the numbers, which he has taken. Each player tries to achieve more points from other. If both players play optimally and player A starts the game then how much more point can player A get than player B?

Input
Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case contains a blank line and an integer N (1 ≤ N ≤ 100) denoting the size of the array. The next line contains N space separated integers. You may assume that no number will contain more than 4 digits.

Output
For each test case, print the case number and the maximum difference that the first player obtained after playing this game optimally.

Sample Input
Output for Sample Input
2

4
4 -10 -20 7

4
1 2 3 4
Case 1: 7
Case 2: 10

两个煞笔玩游戏,每次只能从一边取连续的数,至少取一个,可以取完,问两人绝顶聪明下,他们得到的分数差最大多少。

每个人都想拿最多的分数,那就是子状态中对手获得最大值最小的那个状态,直接记忆化搜索就ok。
dp[l][r]表示这个人在l,r区间内先手能拿到的最大分数。
具体看代码,可能理解一些。

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<utility>
#include<sstream>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int t,n;
int dp[105][105],sum[105],a[105];
int dfs(int l,int r)
{
    if(dp[l][r] != -inf)return dp[l][r];
    if(l > r)
        return dp[l][r] = 0;
    if(l == r)
        return dp[l][r] = a[l];
    int ans = -inf;
    for(int i = l + 1;i <= r + 1;i++)
        ans = max(ans,sum[r] - sum[l - 1] - dfs(i,r));
    for(int i = r - 1;i >= l - 1;i--)
        ans = max(ans,sum[r] - sum[l - 1] - dfs(l,i));
    return dp[l][r] = ans;
}
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\ΡΡ\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\ΡΡ\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int kase = 1;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i = 1;i <= n;i++)
            scanf("%d",a + i);
        sum[0] = 0;
        for(int i = 0;i <= n + 2;i++)
            for(int j = 0;j <= n + 2;j++)
            dp[i][j] = -inf;
        for(int i = 1;i <= n;i++)
            sum[i] = sum[i - 1] + a[i];
        printf("Case %d: %d\n",kase++,2*dfs(1,n) - sum[n]);
    }
    return 0;
}
DSI3协议介绍 分布式系统接口(DSI)是一种通用且功能强大的总线协议,旨在将多个遥感器和执行器设备互连到中央控制模块。该网络的主要目标应用是汽车安全系统。这种应用的一些特点是需要低成本、高鲁棒性、中速互连,仅限于两根导线。此外,它必须具有故障安全性、确定性和良好的EMC特性。即使具有所有级别的智能和可编程性的设备都可以连接到网络,远程设备也必须能够通过简单的状态机实现。由于模块尺寸非常重要,因此中央模块和远程单元中的最小组件至关重要。 阅读详情

相关推荐

Mac查看以太网信息,IP地址,查看配置桥接网络,使得虚拟机和本机ping通--linux系统part

4. 在本机的终端中使用ping命令,查看是否能够ping通虚拟机系统,如下图所示已经ping通。3-查看IP为192.168.1.244,还可以看到一些具体信息,如TCP/IP,DNS等;2-打开centos,进入管理员root模式(使用su命令加上输入管理员密码)然后使用ifconfig命令查看端口地址,如下所示为192.168.1.248。3-在虚拟机内使用ping命令,测试是否和网络连通,如下图所示已经ping通。打开虚拟机设置-点击网络适配器-选择桥接网络。1-打开设置,选择网络。

m0_65485230的博客 1546

1031 - Easy Game 简单区间DP

1031 - Easy Game   You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more num...

pxlsdz的博客 643

高速窄脉冲峰值保持设计

一、目的 在激光探测领域,探测器发出的高速窄脉冲,单片机AD进行采样,很难捕捉到窄脉冲的幅值,即使使用高速AD进行采样,也存在一定的难度。因此,本方案设计了一种高速窄脉冲峰值保持电路,有助于单片机AD采样能很好的捕捉到脉冲幅值。 二、方案分析与比较 峰值保持器一般分为两种:电压型和跨导型。 方案一:电压型峰值保持器,由电压型运放、二极管、保持电容、缓冲器组成,优点是元件成本低,缺点是峰值保持存在过...

weixin_43184208的博客 9284

lightoj 1031 - Easy Game(区间DP)

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or

SSimpLe_Y的博客 1142

别再死记硬背了!用Multisim仿真5分钟搞懂运放电压跟随器到底要不要加反馈电阻

本文通过Multisim仿真实验,深入解析运放电压跟随器中反馈电阻的必要性。实验对比不同阻值对电路性能的影响,揭示反馈电阻在提供偏置电流通路、提升高频稳定性和ESD保护中的关键作用,并给出工程实践中的优化建议,帮助工程师快速掌握运放电路设计要点。

weixin_42641998的博客 371

从AI画稿到3D虚拟时装:Illustrator与Substance 3D的服装设计工作流

本文旨在解决传统服装与纺织品设计师在产品开发流程中,面临的“2D印花图案无法直观预见3D上身效果”、“物理打样成本高昂且周期漫长”的核心痛点。我们将介绍一套纯数字化的3D可视化工作流,核心是利用 Adobe Illustrator 进行矢量印花图案创作,通过 Adobe Substance 3D Sampler 将其转化为逼真的PBR(基于物理渲染)布料材质,并最终在 Adobe Substance 3D Stager 中,将该材质应用于3D服装模型,渲染出照片级的虚拟样衣。本指南将帮助设计师以极低的成本和

Kingsdesigner的博客 1395

LightOJ 1031 - Easy Game(概率)

题目链接:LightOJ 1031 - Easy Game代码#include <cstdio> #include <cstring> #include <algorithm>using namespace std; const int maxn = 105;int N, A[maxn], S[maxn], dp[maxn][maxn]; bool vis[maxn][maxn];void init

不慌不忙、不急不躁 802

华为防火墙双线路配置实战:5分钟搞定主备自动切换(含健康检查避坑指南)

本文详细介绍了华为防火墙双线路配置实战,包括主备自动切换和健康检查机制的优化技巧。通过智能健康检查机制,华为防火墙能实现毫秒级故障自动切换,确保网络高可用性。文章提供了从架构设计到实战配置的全流程指南,并分享了常见配置误区与解决方案,帮助中小企业快速搭建稳定可靠的网络架构。

weixin_30872337的博客 604

训练赛 An Easy Game(dp)

http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=158#problem/C 感觉这道题是应该做出来的。。太挫了,没找到状态方程。 大致题意:输入n,k,m,以及两个长度为n的只含01的字符串,每次你可以选m个数字转换,即将0变1,1变0,需要经过k次变换使第一个字符串变为第二个字符串。 这题把数组设出来就容

1104

深度强化Q学习-基于微软AirSim仿真环境的自动驾驶案例(原理代码详解简易可行)

最近在学习《强化学习原理与Python实现》,肖智清著。参考第十二章的自动驾驶案例,写一篇总结,尽量做到简单可行,让有志于自动驾驶的小伙伴可以通过此篇博客可以管中窥豹,初步了解自动驾驶的强化学习训练过程。 本篇将自动驾驶问题转化为回合制的强化学习任务,设计以车辆观察图像和运行状态为输入的自动驾驶算法,并在AirSim仿真环境中进行训练和测试。本篇使用带经验回放和目标网络的基于深度Q网络算法设计并实现智能体,对经验回放、目标网络和深度Q学习算法进行简单介绍,并用代码实现。

shao918516的博客 8599

Allegro输出光绘文件规范

添加钻孔表的具体步骤为:1.通过屏幕右边的Visibility选项的Views列表,将Drill层打开2.将Visibility选项中的PIN和Via选项都选中,见下图所示: 参数设好之后关闭NC Drill/Parameters窗口,输出数控机床钻孔文件的命令菜单为:Manufacture=>NC=>NC Drill…,打开的窗口如下: 输出数控机床钻孔文件的具体步骤为: 上图是光绘输出的层控制窗口,还有一个窗口是输出参数的控制窗口,我们通过点击上图的第二个列表项General Parameters来

axingxiansen的博客 2807

FZU-2146 Easy Game

#include <iostream> #include <cstdio> #include <cstring> #include <string>using namespace std;int t, cas; string str;int main() { cas = 0; scanf("%d", & t); while(t --) { cin >>

Kiyonami Yu 472

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

博弈背景下的dp与记忆化搜索 (两个例题 LightOJ - 1031 Easy Game HDU - 4597 Play Game)

对于某些dp,是在博弈的基础上的,针对这些题目,我们不妨设 dp[某一阶段],为该阶段先手的最优子结构 那么对于他的状态转移: dp[下一状态] = max(忽视对手的最优情况 - dp[上一状态]) 尝试理解:因为博弈中,一个状态的先手,在上一状态是后手,而对手是先手,所以dp[上一状态]其实是对手的最优状态,所以有在忽视对手的最优情况 - 上一状态对手的最优情况。 比较抽象,下面看两个...

平凡人Kalzn的博客 353

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

lightoj 1031 - Easy Game 博弈类区间DP

给定一个长度为n的序列,每次只能从两边选取任意个数字,然后两个足够 聪明的人玩这个游戏,问先手比后手选的值多多少。 对于[1,n]肯定先手A先选取一段区间,然后剩下的一段区间那么后手B就成了先手,同理,先后手交替进行。 对于A来言,下一步B先手的区间内B比A大x,那么这一步区间内A比B大 (A的选取值-x)。同理对B有效 那么所有的区间都变得相同了,都是找区间内先手比后手大多少,[1,n]以

440

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

lightoj 1031 Easy Game (区间dp 博弈)

lightoj 1031 Easy Game (区间dp 博弈)

Tc的专栏 1512

【LightOJ - 1031】Easy Game (区间dp,博弈)

题干: You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the le...

xuanweiace的博客 564

LightOJ - 1031 Easy Game(区间DP)

题目大意:有一种包含N个数字的游戏和两个选手,选手A先手,游戏规则如下 1.每次只能从左往右拿或者从右往左拿1-m个,不能两边同时拿 2.总数和大的获胜解题思路:用dp[i][j]表示[i,j]选手A先手,所能得到的最大数字和 则转移方程为dp[i][j] = max(sum[k] - sum[i - 1] + sum[j] - sum[k] + dp[k + 1][j]) 表示的是拿了[i

静静地码 518

Easy Game(博弈dp,区间dp)

https://cn.vjudge.net/problem/LightOJ-1031 You are playing a two player game. Initially there areninteger numbers in an array and playerAandBget chance to take them alternatively. Each player c...

永夜莫明的博客 519

lightoj 1031 - Easy Game 【区间dp】

题目链接:lightoj 1031 - Easy Game 1031 - Easy Game PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are playing a two player game. Initially there are n intege

世界很大 778

lightoj1031 - Easy Game【区间dp】

1031 - Easy Game     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are playing a two player game. Initially there are n intege

走一步再走一步 720

LightOJ-1031 博弈 区间DP

1031 - Easy Game     PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You are playing a two player game. Initially there are n intege

AC_Machine的博客 566

LightOJ 1031 Easy Game(区间DP)

题意:A,B轮流从左或从右以最优策略选出连续的几个数,直至选完,求两人所选数和差的最小值。 思路:dp[i][j]表示先手者A选区间[i, j]的最优策略和。A要让B得到的和最小,所以先求出让B最优策略得到的最小数字和,即 tmp = min(dp[i][k], dp[k+1][j]),其中 i #include #include #include #include #include

ACMiao的博客 442

LightOJ 1031 - Easy Game【区间dp】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031题意: 给一个序列,两个人轮流在序列的两边取任意个数的number,但每次只能从选定的那一边取,问取得数字的和的较大者比较小者多多少?思路: dp[i][j]表示i-j区间的最优解,然后枚举区间。代码:#include <cstdio> #include <cstring

mfcheer 895

Light OJ_1031 Easy Game

轻触即可提交代码 Time limit 2000 ms Memory limit 32768 kB Source Special Thanks: Jane Alam Jan (Dataset) 题目要求: You are playing a two player game. Initially there areninteg...

From now on...的Blogs 161

LightOJ1031-Easy Game-记忆化搜索+博弈

You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more numbers from the left or...

Nothing_but_Fight的博客 276

LightOJ 1031 Easy Game (区间DP)

<题目链接> 题目大意: 给定一段序列,两人轮流取数,每人每次只能从序列的两端的任意一段取数,取的数字位置必须连续,个数不限,问你这两人取数的最大差值是多少。 解题分析: 每人取数时面对的局面是一段连续的子序列,我们不妨假设$dp[l][r]$为对于区间$[l,r]$,两人取数的最大差值。因为可能要进行连续区间的转移,所以我们枚举区间之后,还要枚举断点。先预处理出前缀和,对于区...

weixin_30555753的博客 145
上一篇: Food Delivery(区间DP)
下一篇: 1033 - Generating Palindromes(傻DP)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值