HDU 4597 Play Game 记忆化DP
Play Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Each case contains 3 lines. The first line is the N (N≤20). The second line contains N integer ai (1≤ai≤10000). The third line contains N integer bi (1≤bi≤10000).
1
2
5
10 100
2 4 3
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
int a[] ,b[] ;
int suma[] ,sumb[] ;
int dp[][][][] ;
int N ; int dfs(int U , int B ,int L ,int R){
if(dp[U][B][L][R] != -)
return dp[U][B][L][R] ;
if(U > B && L > R)
return dp[U][B][L][R] = ;
int sum = ;
if(U <= B)
sum += suma[B] - suma[U-] ;
if(L <= R)
sum += sumb[R] - sumb[L-] ;
int nowstate = ;
if(U == B)
nowstate = Max(nowstate , sum - dfs(U+,B-,L,R)) ;
else if(U < B){
nowstate = Max(nowstate , sum - dfs(U+,B,L,R)) ;
nowstate = Max(nowstate , sum - dfs(U,B-,L,R)) ;
}
if(L == R)
nowstate = Max(nowstate , sum - dfs(U,B,L+,R-)) ;
else if(L < R){
nowstate = Max(nowstate , sum - dfs(U,B,L+,R)) ;
nowstate = Max(nowstate , sum - dfs(U,B,L,R-)) ;
}
return dp[U][B][L][R] = nowstate ;
} int main(){
int T ;
scanf("%d",&T) ;
while(T--){
scanf("%d",&N) ;
suma[] = sumb[] = ;
for(int i = ; i <= N ; i++){
scanf("%d",&a[i]) ;
suma[i] = suma[i-] + a[i] ;
}
for(int i = ; i <= N ; i++){
scanf("%d",&b[i]) ;
sumb[i] = sumb[i-] + b[i] ;
}
memset(dp,-,sizeof(dp)) ;
printf("%d\n",dfs(,N,,N)) ;
}
return ;
}
HDU 4597 Play Game 记忆化DP的更多相关文章
- HDU 4597 Play Game (记忆化搜索博弈DP)
题意 给出2*n个数,分两列放置,每列n个,现在alice和bob两个人依次从任意一列的对头或队尾哪一个数,alice先拿,且两个人都想拿最多,问alice最后能拿到数字总和的最大值是多少. 思路 4 ...
- hdu 4597 Play Game(记忆化搜索)
题目链接:hdu 4597 Play Game 题目大意:给出两堆牌,仅仅能从最上和最下取,然后两个人轮流取,都依照自己最优的策略.问说第一个人对多的分值. 解题思路:记忆化搜索,状态出来就很水,dp ...
- HDU 4597 Play Game(记忆化搜索,深搜)
题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...
- Google Code Jam 2009, Round 1C C. Bribe the Prisoners (记忆化dp)
Problem In a kingdom there are prison cells (numbered 1 to P) built to form a straight line segment. ...
- UVA - 11324 The Largest Clique 强连通缩点+记忆化dp
题目要求一个最大的弱联通图. 首先对于原图进行强连通缩点,得到新图,这个新图呈链状,类似树结构. 对新图进行记忆化dp,求一条权值最长的链,每一个点的权值就是当前强连通分量点的个数. /* Tarja ...
- cf835(预处理 + 记忆化dp)
题目链接: http://codeforces.com/contest/835/problem/D 题意: 定义 k 度回文串为左半部分和右半部分为 k - 1 度的回文串 . 给出一个字符串 s, ...
- cf779D(记忆化dp)
题目链接: http://codeforces.com/problemset/problem/799/D 题意: 给出两个矩阵边长 a, b, 和 w, h, 以及一个 c 数组, 可选择 c 数组中 ...
- Codeforces1107E Vasya and Binary String 记忆化dp
Codeforces1107E 记忆化dp E. Vasya and Binary String Description: Vasya has a string \(s\) of length \(n ...
- POJ 1088 滑雪(简单的记忆化dp)
题目 又一道可以称之为dp的题目,虽然看了别人的代码,但是我的代码写的还是很挫,,,,,, //看了题解做的简单的记忆化dp #include<stdio.h> #include<a ...
随机推荐
- Winform用匿名方法新建线程的方法
作用:1.将耗时的操作放在单独的线程,加快UI的响应速度.Thread t = new Thread(delegate() { parse.ParseDay(StockCode, FileName); ...
- 【linux】关机重启命令
shutdown: [参数][时间] -h:关机 -r:重启 -c:取消上一次关机或重启 [root@paulinux ~]# shutdown -h now ##马上重启 [root@paulinu ...
- 【phantomjs】使用phantomjs生成highChart的图片(待完善)
阅读目录 //center }, subtitle: { text: 'Source: WorldClimate.com', x: -20 }, xAxis: { categories: ['Jan' ...
- Enable EPEL Repository for RHEL/CentOS 7.x/6.x/5.x
This howto guide shows you’ll how to enable EPEL repository under RHEL/CentOS 6/5 to install additio ...
- HAML学习
来源:http://ningandjiao.iteye.com/blog/1772845 一个技术能够风靡,一定是有它的原因的,在熟悉之前,我们没有资格去对它做任何的判断. Haml 是一种简洁优美的 ...
- 20160720-java高并发
https://www.zhihu.com/search?type=content&q=tomcat+%E8%83%BD%E6%94%AF%E6%8C%81%E5%A4%9A%E5%B0%91 ...
- [Java Web – Maven – 1A]maven 3.3.3 for windows 配置(转)
1.环境 系统环境:windows 2008 R2 JDK VERSION: 1.7.0_10 2.下载地址 MAVEN 下载地址:http://maven.apache.org/download.c ...
- POJ 1986 DIstance Query LCA水题
给出一棵树,对于每一个询问,给出2个节点,输出2个节点的距离. 输入中有字母,那个是没有用的,不用管. 思路: 0.选择编号为1的节点作为树的root (注意:有些题的边是单向的,这时候我们要根据节点 ...
- xhprof 安装使用
1.安装扩展 windows下把 xhprof.dll 放到extensions目录下 修改配置文件 [xhprof] extension=xhprof.so; ; directory used by ...
- linux shell 中的位置变量
对于linux shell 中的位置变量,我一直以来都是吐不出来又咽不下去,每次看到都不懂,不懂了就去百度google,看完了又忘,真是慢性咽炎啊.现在认真想想也是,其实自己一直以来都没有好好学习过, ...