HDU - 4597 Play Game(博弈dp)
Play Game
InputThe 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≤bi≤10000).OutputFor 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; int a[],b[];
int dp[][][][]; int dfs(int al,int ar,int bl,int br,int sum){
if(al>ar&&bl>br){
return ;
}
if(dp[al][ar][bl][br]>-) return dp[al][ar][bl][br];
int ma=;
if(al<=ar){
ma=max(ma,sum-dfs(al+,ar,bl,br,sum-a[al]));
ma=max(ma,sum-dfs(al,ar-,bl,br,sum-a[ar]));
}
if(bl<=br){
ma=max(ma,sum-dfs(al,ar,bl+,br,sum-b[bl]));
ma=max(ma,sum-dfs(al,ar,bl,br-,sum-b[br]));
}
dp[al][ar][bl][br]=ma;
return ma;
}
int main()
{
int t,n,i,j;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
int sum=;
for(i=;i<=n;i++){
scanf("%d",&a[i]);
sum+=a[i];
}
for(i=;i<=n;i++){
scanf("%d",&b[i]);
sum+=b[i];
}
memset(dp,-,sizeof(dp));
printf("%d\n",dfs(,n,,n,sum));
}
return ;
}
HDU - 4597 Play Game(博弈dp)的更多相关文章
- hdu 4597 Play Game 区间dp
Play Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=459 ...
- hdu 4597 Play Game(区间dp,记忆化搜索)
Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N card ...
- HDU 4597 Play Game (DP,记忆化搜索)
Play Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total S ...
- 博弈dp入门 POJ - 1678 HDU - 4597
本来博弈还没怎么搞懂,又和dp搞上了,哇,这真是冰火两重天,爽哉妙哉. 我自己的理解就是,博弈dp有点像对抗搜索的意思,但并不是对抗搜索,因为它是像博弈一样,大多数以当前的操作者来dp,光想是想不通的 ...
- hdu 4778 Gems Fight! 博弈+状态dp+搜索
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4102743.html 题目链接:hdu 4778 Gems Fight! 博弈+状态dp+搜 ...
- HDU 5623 KK's Number (博弈DP)
KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...
- hdu 4597 Play Game(记忆化搜索)
题目链接:hdu 4597 Play Game 题目大意:给出两堆牌,仅仅能从最上和最下取,然后两个人轮流取,都依照自己最优的策略.问说第一个人对多的分值. 解题思路:记忆化搜索,状态出来就很水,dp ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- hdu 5094 Maze 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...
- hdu 2829 Lawrence(斜率优化DP)
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和. ...
随机推荐
- 1625 codevs数字金字塔
1625 数字金字塔 USACO 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 考虑在下面被显示的数字金字塔. 写 ...
- loopqueue
import java.util.Arrays; public class loopQueue <E>{ public Object[] data=null; private int ma ...
- Angular 隨記
Windows下更新Node 和NPM方法 管理員模式打開powershell 執行以下命令: Set-ExecutionPolicy Unrestricted -Scope CurrentUser ...
- NSString *const 和 const NSString * 的区别
1.变量存储的指针可变,变量存储的值不可变 //A modifiable pointer to a constant NSString (its value can't be modified) &q ...
- poj 3463 Sightseeing——次短路计数
题目:http://poj.org/problem?id=3463 当然要给一个点记最短路和次短路的长度和方案. 但往优先队列里放的结构体和vis竟然也要区分0/1,就像把一个点拆成两个点了一样. 不 ...
- JavaScript创建对象的几种重要模式
一.工厂模式 1. 代码示例 function person(name, age) { var p = new object(); p.name = name; p.age = age; p.sayN ...
- ORA-12514: TNS: no listener 解决方案
服务端:oracle 11g 客户端: pl/sql 问题描述: 用客户端 pl/sql 连接登录的时候,提示 "ORA-12514: TNS: no listener". 在服务 ...
- JSF使用HTML5的custom attribute
只需要在页面引用这样的命名空间: xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"之后,在JSF的控件的html5属性加上前缀&quo ...
- (转)C#用Linq实现DataTable的Group by数据统计
本文转载自:http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1.用两层循环计算,前提条件是数据已经按分组的列排好序 ...
- webrtc doubango linphone
1.doubango官网:http://www.doubango.org/ 2.doubango是一个开源的VOIP基础平台, 并能用于嵌入式和桌面系统的开源框架,该框架使用ANSCI-C编写,具有很 ...