Play Game

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4597

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

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

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

HINT

题意

有两排数,AB依次拿,每次只能从第一/二排最左边和最右边拿

问你A拿的和是多少,假设两个人都是很聪明的

题解:

出现聪明这个词的时候,这种题不是博弈论就是dp吧

很显然这道题是一个区间dp

直接跑就好了

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int dp[][][][]; int a[maxn];
int b[maxn];
int temp;
int solve(int l1,int r1,int l2,int r2)
{
if(dp[l1][r1][l2][r2]!=-)
return dp[l1][r1][l2][r2];
if(l1>r1||l2>r2)
dp[l1][r1][l2][r2]=;
int sum=;
int ans=;
if(l1<=r1)
sum+=a[r1]-a[l1-];
if(l2<=r2)
sum+=b[r2]-b[l2-];
if(l1<=r1)
{
ans=max(ans,sum-solve(l1+,r1,l2,r2));
ans=max(ans,sum-solve(l1,r1-,l2,r2));
}
if(l2<=r2)
{
ans=max(ans,sum-solve(l1,r1,l2+,r2));
ans=max(ans,sum-solve(l1,r1,l2,r2-));
}
return dp[l1][r1][l2][r2]=ans;
}
int main()
{
//test;
int t=read();
while(t--)
{
memset(dp,-,sizeof(dp));
memset(a,,sizeof(a));
memset(b,,sizeof(b));
int n=read();
for(int i=;i<=n;i++)
{
temp=read();
a[i]+=a[i-]+temp;
}
for(int i=;i<=n;i++)
{
temp=read();
b[i]+=b[i-]+temp;
}
cout<<solve(,n,,n)<<endl;
}
}

hdu 4597 Play Game 区间dp的更多相关文章

  1. hdu 4597 Play Game(区间dp,记忆化搜索)

    Problem Description Alice and Bob are playing a game. There are two piles of cards. There are N card ...

  2. HDU 5115 Dire Wolf 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5115 Dire Wolf Time Limit: 5000/5000 MS (Java/Others ...

  3. HDU 5693 D Game 区间dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5693 题解: 一种朴实的想法是枚举选择可以删除的两个或三个数(其他的大于三的数都能凑成2和3的和), ...

  4. hdu 5693 && LightOj 1422 区间DP

    hdu 5693 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5693 等差数列当划分细了后只用比较2个或者3个数就可以了,因为大于3的数都可以由2和3 ...

  5. hdu 4745 Two Rabbits 区间DP

    http://acm.hdu.edu.cn/showproblem.php?pid=4745 题意: 有两只兔子Tom Jerry, 他们在一个用石头围城的环形的路上跳, Tom只能顺时针跳,Jerr ...

  6. hdu 5181 numbers——思路+区间DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...

  7. HDU 1141---Brackets Sequence(区间DP)

    题目链接 http://poj.org/problem?id=1141 Description Let us define a regular brackets sequence in the fol ...

  8. HDU 4632 Palindrome subsequence(区间dp,回文串,字符处理)

    题目 参考自博客:http://blog.csdn.net/u011498819/article/details/38356675 题意:查找这样的子回文字符串(未必连续,但是有从左向右的顺序)个数. ...

  9. hdu 2476(第一道区间dp)

    题意:就是给定两个字符串,第一个是初始串,第二个是目标串,问你把初始串变到目标串最少需要多少串! 分析:此题分两步,第一步是假设开始的初始串是空串,然后就进行区间dp,dp[i][j]代表把区间[i, ...

随机推荐

  1. 时间日期Date类型

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  2. TopFreeTheme精选免费模板【20130629】

    今天给大家推荐9款最新精选的WordPress主题,它们涵盖了新闻.杂志.博客.房地产方面的主题.有些是商业模板,但现在都可以免费下载. GeoPlaces v4.6.2 – 来自Templatic的 ...

  3. 第三百三十六天 how can I 坚持

    家里断网了,忘交网费了,连的手机网络,也挺好,吃完饭就可以睡觉了. 不知道怎的,昨天和家人聊天,一提对象的事就很容易着急生气,然后就会后悔..哎,这脾气得改. 确实不知道自己的另一半是啥样,想象不出来 ...

  4. bpl

    RegisterClass LoadPackage Getprocaddress FindClass UnRegisterModuleClasses UnloadPackage

  5. 让CSS3给你的文字加上边框宽度,并实现镂空效果

    这次,我主要向大家介绍一下CSS3下的-webkit-text-stroke属性,并分享几个用该属性制作的镂空文字效果. 1.-webkit-text-stroke属性简介 CSS边框的一个不足就是只 ...

  6. POJ 2888 Magic Bracelet(Burnside引理,矩阵优化)

    Magic Bracelet Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 3731   Accepted: 1227 D ...

  7. POJ 1410 Intersection(判断线段交和点在矩形内)

    Intersection Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9996   Accepted: 2632 Desc ...

  8. C# winform只有一个进程

    在做winform程序的时候,有时候需要客户只能起一个进程,不能起多个进程,用如下代码可以实现. internal static class Program { private static Mute ...

  9. hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)

    http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS     Me ...

  10. 【破解三网】iphone5 国行 A1429

    教程仅适用于A1429的I5. 1.首先把sim卡插入手机.关闭蜂窝数据里面的"蜂窝移动数据"还有打开漫游里面的"语音漫游".如图               ...