HDU 4597 Play Game(记忆化)

HDU4597:Play Game(记忆化搜索(dp))(博弈) Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from either pile, and the sc 阅读详情

Play Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 894    Accepted Submission(s): 525


Problem Description
Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from either pile, and the score of the card will be added to his total score. Alice and Bob are both clever enough, and will pick up cards to get as many scores as possible. Do you know how many scores can Alice get if he picks up first?
 

Input
The first line contains an integer T (T≤100), indicating the number of cases.
Each case contains 3 lines. The first line is the N (N≤20). The second line contains N integer a i (1≤a i≤10000). The third line contains N integer b i (1≤b i≤10000).
 

Output
For each case, output an integer, indicating the most score Alice can get.
 

Sample Input
  
2 1 23 53 3 10 100 20 2 4 3
 

Sample Output
  
53 105
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   5235  5234  5233  5232  5231 
 



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef __int64 ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 22

int a[N],b[N];
int dp[N][N][N][N];
int n;
int suma[N],sumb[N];

int dfs(int le,int ri,int lle,int rri)
{
	if(dp[le][ri][lle][rri]!=-1) return dp[le][ri][lle][rri];
	int i,j;
	int temp=0;

    if(le>ri&&lle>rri)
			return dp[le][ri][lle][rri]=0;
	temp+=suma[ri]-suma[le-1];
	temp+=sumb[rri]-sumb[lle-1];
	int ans=0;

	if(le<=ri)
	{
		ans=max(ans,temp-dfs(le+1,ri,lle,rri));
		ans=max(ans,temp-dfs(le,ri-1,lle,rri));
	}
   if(lle<=rri)
	{
		ans=max(ans,temp-dfs(le,ri,lle+1,rri));
		ans=max(ans,temp-dfs(le,ri,lle,rri-1));
	}
   return dp[le][ri][lle][rri]=ans;
}

int main()
{
	int i,j;
	int t;
	sf(t);
	while(t--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			suma[i]=suma[i-1]+a[i];
		}
        for(i=1;i<=n;i++)
		{
			sf(b[i]);
			sumb[i]=sumb[i-1]+b[i];
		}
	   mem(dp,-1);
       pf("%d\n",dfs(1,n,1,n));
	}
  return 0;
}





【Linux】实际项目应该如何完成?--安防监控系统项目的总结 到目前为止我也做个5、6个嵌入式项目,但以往都是从零开始自己做,也就是毫无计划,想到那里做那里,有想法就会去实现,就这样导致我碰到了很多坑,也消耗了我许多时间,当然,不是说这样不好,因为在其中我也得到了一个很好的锻炼与练习,但是这不适用于在工作中去这样做。... 阅读详情

相关推荐

Windows安装WSL子系统及docker,以及WSL和docker配置、使用及问题解决

在Windows操作系统中,Ubuntu子系统(也称为Windows Subsystem for Linux, WSL)为开发者提供了一个在Windows环境下运行Linux环境的平台。然而,有时用户在按照Ubuntu子系统或者使用WSL时,可能会遇到各种问题,下面总结一下解决方式。想要在Windows上安装Docker(实际上是基于Hyper-V或者WSL2这两项虚拟化技术),需要开启虚拟化功能,所以不管是对于系统还是硬件都有一定的要求。

sym的博客 9782

hdu 4597 Play Game(记忆化搜索)

题目链接:hdu 4597 Play Game 题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,问说第一个人对多的分值。 解题思路:记忆化搜索,状态出来就非常水,dp[fl][fr][sl][sr][flag],表示第一堆牌上边取到fl,下面取到fr,同样sl,sr为第二堆牌,flag为第几个人在取。如果是第一个人,dp既要尽量大,如果是第二个

不慌不忙、不急不躁 1397

STM32开发者必看:如何在正点原子探索者开发板上快速移植CANopenNode协议栈

本文为STM32开发者提供了在正点原子探索者开发板上快速移植CANopenNode协议栈的实战指南。文章详细介绍了从环境准备、硬件抽象层适配到协议栈初始化与测试的全过程,并分享了PDO配置与性能优化等关键技巧,帮助开发者高效实现CANopen标准化通信。

weixin_29173777的博客 462

HDU 4597 Play Game 记忆化搜索

HDU 4597 Play Game  题目链接

n-1 792

从CMT2300A实战出发:Sub1G射频匹配电路设计要点与315MHz应用详解

本文从CMT2300A芯片实战出发,详细解析Sub1G射频匹配电路设计要点,特别针对315MHz应用场景。内容涵盖频段划分逻辑、调制方式选择、晶体振荡器设计等基础认知,以及315MHz匹配电路物料选型、巴伦网络处理等实战技巧,并分享PCB布局防干扰设计和实测验证方法,助力开发者优化射频通信性能。

weixin_29238147的博客 163

STM32F103C8T6 Bootloader开发实战:串口IAP固件升级与Keil工程配置详解

本文详细介绍了STM32F103C8T6 Bootloader开发实战,重点讲解串口IAP固件升级的实现方法与Keil uVision5工程配置。通过Flash分区管理、USART1通信协议设计及应用程序跳转机制等核心技术,帮助开发者掌握嵌入式系统固件升级方案,提升设备维护效率。

weixin_29165725的博客 436

hdu4597Play Game 记忆化搜索

//两堆数量为n(n<=20) 的牌,每个牌都有份数 //两个人轮流拿牌,可以取两堆数的头或者尾中的一张 //每个人都取最优解 //问第一个人能够取得的最大分数 //记忆化搜索 dp[sa][ta][sb][tb] 表示第一堆剩下sa,ta,第二堆剩下 //sb,tb的最大值 #include #include #include using namespace std ; const int m

ijbuhv的专栏 610

200Gb/s以上速率的通道信号完整性设计和优化经验(二)

为满足200Gb/s信号完整性需求,需综合优化PCB、连接器、封装及SERDES架构。关键措施包括:采用低粗糙度铜箔与低损耗材料降低传输线损耗(200G目标0.55–0.6dB/cm);通过背钻工艺控制残桩长度至4±2mil;缩减连接器焊盘残桩至600μm以内以消除谐振;封装层面推进跳层走线、低Dk/Df材料与可控SMT工艺;采用PAM4调制与基于ADC/DSP的混合信号架构实现高效均衡。先进CMOS工艺(如纳米片器件)支撑复杂数字处理,协同设计是突破速率瓶颈的核心。

小孟同学的博客 148

HDU 4597-Play Game-记忆化搜索

Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from either pile, and the s...

Nothing_but_Fight的博客 239

IEC61850规约客户端软件开发实战(第二章)

本文介绍了基于IEC61850规约的客户端软件开发过程,重点阐述功能界面设计和服务端连接功能的实现。界面采用Qt框架设计,包含功能按钮区、数据模型展示区(使用QTreeWidget)和状态显示区。连接功能通过libiec61850开源库实现,详细说明了连接流程、句柄创建及状态管理的代码实现。测试结果表明系统能正确识别连接状态,并通过界面直观显示。文章为IEC61850规约软件开发提供了实用参考,下期将分享规约模型数据加载的实现过程。

半青年的博客 2855

HyperLynx(十三)Hyperlynx前放置之对网络的EMC分析

在“Spectrum Analyzer”对话框的“Stimulus”(激励)栏中,设置激励源频率为100MHz,选择“IC modeling”为“Fast-Strong”,并按图所示设置其他选项。显然,在仿真的基频上,它的幅值最大,将鼠标光标置于柱状图上,可以读取其值为64.28mA,这个数值是由选定的驱动芯片决定的。按上图所示的原理图,在接收端增加一个并联的RC负载,再次运行仿真,结果如图所示。在对话框左侧的“Pins”列表中,显示出了已添加电流探针的引脚,可以在此列表中选择所要仿真的目标。...

小幽余生不加糖 4678

Play Game (HDU 4597)(dp, 记忆化搜索)

题目: Play Game - HDU 4597 - Virtual Judge Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from either pile, and the score of the.

weixin_53484451的博客 236

【Bug已解决】Failed to fetch version ECONNREFUSED 解决方案

方案适用场景推荐指数难度方案一:NODE_EXTRA_CA_CERTS代理/企业网关证书⭐⭐⭐⭐⭐低方案二:浏览器导出证书不知证书在哪⭐⭐⭐⭐中方案三:使用系统证书macOS 用户⭐⭐⭐⭐中方案四:关闭代理直连快速验证⭐⭐⭐低方案五:更新 Node.js证书列表过时⭐⭐⭐低方案六:同步系统时间时间偏差导致⭐⭐⭐低根本原因。

博客 9973

hdu 4597 Play Game【记忆化搜索】

Play Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 805    Accepted Submission(s): 464 Problem Description Alice and Bob are play

letterwuyu的专栏 937

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

HDU 4597 Play Game 记忆化搜索

这道题还是去长春之前看的,当时以为是博弈什么的。后来学长是记忆化搜索,当时连简单的DP都不会,只好先扔到一边了。 dp[s1][e1][s2][e2] 表示第一排剩[s1,e1] ,第二排剩 [s2,e2] 时的最优决策。 dp[s1][e1][s2][ e2 ] = sum - min(dfs(s1,e1,s2+1,e2),dfs(s1,e1,s2,e2-1),dfs(s1+1,e1,s2,

自在飞花 974

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

hdu 4597 Play Game (记忆化搜索)

Play Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 35    Accepted Submission(s): 24 Problem Description Alice and Bob are

To be what you what to be! 2211

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

HDU 4597 Play Game (简单博弈记忆化搜索 )

传送门 定义f[l][r][q][w]f[l][r][q][w]f[l][r][q][w]为在第一堆前面拿了lll个,在后面拿了rrr个 在第二堆前面拿了qqq个,在后面拿了www个,目前人的期望收益 若从第一堆前面拿,转移是,其中sumnsumnsumn是目前还剩下的石子 sumn−f[l+1][r][q][w]sumn-f[l+1][r][q][w]sumn−f[l+1][r][q][w] 若从第一堆后面拿,转移是 sumn−f[l][r+1][q][w]sumn-f[l][r+1][q][w]sumn

jziwjxjd的博客 513

HDU 4597 Play Game (DP,记忆化搜索,博弈)

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=4597 大致题意:给出2堆数,Alice和Bob轮流拿,每次只能从每堆数的头或尾取,Alice先取,两人都采取最优策略,求Alice最后最多能拿的数的和。 思路:四维dp[ l1 ] [ r1 ] [ l2 ] [ r2 ],表示当前第一堆剩下的区间为(l1,r1),第二堆剩下的区间为

男人就应该默默地努力--某一男人 796

HDU 4597 Play Game(四维记忆化搜索)

做之前问虎哥比赛的时候怎么过掉的,虎哥说秒过。感觉自己好水啊。。。。 四维记忆化搜索。决策的条件是如果你剩下的数越小你得到的数越大。dp[l1][r1][l2][r2]代表当前状态的最优的情况。 dp[l1][r1][l2][r2] = sum-{四种衍生出来的状态}; Play Game Time Limit: 2000/1000 MS (Java/Others)    Me

I am a slow walker, but I never walk backwards! 1020

HDU 4597 Play Game(记忆化搜索)

Play Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1704    Accepted Submission(s): 1014 Problem Description Alice and Bob ar

Com_ice的博客 343

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

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

平凡人Kalzn的博客 353

hdu 4597 Play Game 记忆化搜索 区间dp

题意: 给你两摞牌,每次可以任意一堆 的牌头或者牌尾抽牌。Alice先抽,Bob后抽,两个人都想抽到最多点数的牌。 做法: dp[az][ay][bz][by]。 az,ay代表第一堆牌左边 和右边 分别抽到第几张了。然后在这个状态下 Bob抽到的点数。 因为dp表示的Bob的点数,所以牌堆里剩余奇数张牌的时候,是Bob抽,要取各种抽法的最大值。如果只剩偶数张牌,那么是Alice抽,要取 各种抽法中 的最小值。

万事屋 931

HDU 4597 Play Game (记忆化搜索)

Play Game Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score...

xcatf的博客 275

HDU 4597 Play Game[博弈论 负值最大函数 记忆化搜索]

题干Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from

micsay的博客 484

HDU4597:Play Game(记忆化)

Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N cards in each pile, and each card has a score. They take turns to pick up the top or bottom card from

ACM!荣耀之路! 2956
上一篇: poj 2923 Relocation(状压dp)
下一篇: wust 1420 We love FibonaQ(矩阵+线段树)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值