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 ...
随机推荐
- Android 查看內存使用
一.使用dumpsys meminfo命令 1.使用dumpsys meminfo查看内存使用情况 2.过滤某个进程可以使用 dumpsys meminfo | grep -i phone 二,使用t ...
- 史上最全Java表单验证封装类
package com.tongrong.utils; import java.util.Collection; import java.util.Map; import java.util.rege ...
- phonegap–app启动欢迎引导页localstorage
对一个新的app,一般情况都会添加一个介绍和欢迎的页面来告诉用户app的功能和新的特性. 那么在phonegap项目里面如何添加这样个引导欢迎页. 这里需要注意的是只有app第一次打开的时候才会有,其 ...
- 支付宝客户端支付配置RSA公钥的问题错误,导致收不到回发通知
没收到通知的原因是你们的商户公钥上传地址弄错了,应该上传到合作伙伴管理,您上传到无线wap哪里了,把您的公钥,从无线wap哪里复制贴到合作伙伴管理即可
- c# 中的多线程和异步
前言: 1.异步和多线程有区别吗? 答案:多线程可以说是实现异步的一种方法方法,两者的共同目的:使主线程保持对用户操作的实时响应,如点击.拖拽.输入字符等.使主程序看起来实时都保持着等待用户响应的状态 ...
- Learning Puppet — Manifests
Begin In a text editor — vim, emacs, or nano — create a file with the following contents and filenam ...
- HttpUrlConnection java.net.SocketException: Software caused connection abort: recv failed
最近做java swing程序在模拟httprequest请求的时候出现了这个错误 java.net.SocketException: Software caused connection abort ...
- 探秘JavaScript中的六个字符
JavaScript 是一个奇怪而有趣的语言,我们可以写一些疯狂却仍然有效的代码.它试图帮助我们把事情转换到基于我们如何对待他们的特定类型. 如果我们添加一个字符串,JavaScript会假定我们希望 ...
- Existence and nonexistence results for anisotropic quasilinear elliptic equations
Fragalà, Ilaria; Gazzola, Filippo; Kawohl, Bernd. Existence and nonexistence results for anisotropic ...
- 优化studio的速度
随着Android Studio开发工具的逐渐成熟,越来越多的程序员选择这种IDE工具来进行开发,但是android studio在使用过程中有时候会出现卡顿问题.在赶项目的时候,遇到这类问题最是苦恼 ...