hdu4597 区间dp
//Accepted 1784 KB 78 ms
//区间dp
//dp[l1][r1][l2][r2] 表示a数列从l1到r1,b数列从l2到r2能得到的最大分值
//
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
;
int dp[imax_n][imax_n][imax_n][imax_n];
int n;
int a[imax_n],sa[imax_n],b[imax_n],sb[imax_n];
int max(int a,int b)
{
return a>b?a:b;
}
int dfs(int l1,int r1,int l2,int r2)
{
) return dp[l1][r1][l2][r2];
dp[l1][r1][l2][r2]=;
]+sb[r2]-sb[l2-]-dfs(l1+,r1,l2,r2);
]+sb[r2]-sb[l2-]-dfs(l1,r1-,l2,r2));
if (l2<=r2)
{
dp[l1][r1][l2][r2]=max(dp[l1][r1][l2][r2],sa[r1]-sa[l1-]+sb[r2]-sb[l2-]-dfs(l1,r1,l2+,r2));
dp[l1][r1][l2][r2]=max(dp[l1][r1][l2][r2],sa[r1]-sa[l1-]+sb[r2]-sb[l2-]-dfs(l1,r1,l2,r2-));
}
return dp[l1][r1][l2][r2];
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
sa[]=;
;i<=n;i++)
{
scanf("%d",&a[i]);
sa[i]=sa[i-]+a[i];
}
sb[]=;
;i<=n;i++)
{
scanf("%d",&b[i]);
sb[i]=sb[i-]+b[i];
}
memset(dp,-,sizeof(dp));
printf(,n,,n));
}
;
}
hdu4597 区间dp的更多相关文章
- hdu4597 Play Game 区间DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4597 全国邀请赛通化赛区第8题--题目重现 思路: 区间DP的思想,想法是队友想出来的,感觉很秒,自己 ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
- 区间DP LightOJ 1422 Halloween Costumes
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...
- BZOJ1055: [HAOI2008]玩具取名[区间DP]
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1588 Solved: 925[Submit][Statu ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- BZOJ 1260&UVa 4394 区间DP
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k ...
- 区间dp总结篇
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报 ...
随机推荐
- 项目解析- JspLibrary - part3
CRUD read: String sql = "select b.*,c.name as bookcaseName,p.pubname as publishing,t.typename f ...
- Java replace() 方法
Java replace() 方法 Java String类 replace() 方法通过用 newChar 字符替换字符串中出现的所有 oldChar 字符,并返回替换后的新字符串. 语法 publ ...
- 发布完ArcGIS地图服务后,服务未启动成功
今天下午更新地图服务后,服务未启动成功.出来的弹出框警告问题目前应该是ArcGIS Server出了问题,打开ArcCatalog目录,查看GIS服务器下localhost下的服务,只要是今天发布的服 ...
- 在ArcMap 10.3中创建和编辑数据
在ArcMap 10.3中创建和编辑数据 .......待补充 新建 创建一个新文件((Points, Polylines, and Polygons/点.线.多边形)
- python2 安装scrapy问题解决方法
错误代码: build/temp.linux-x86_64-:: fatal error: openssl/opensslv.h: 没有那个文件或目录 compilation terminated. ...
- Spring注释与简化配置
在Spring 2.5及以后的版本中,提供了注释和命名空间来简化Spring的配置.下面是一些常用配置分享. 1.@Autowired注释 以前给一个Bean配置属性时,Bean必须配置< ...
- Permutation Sequence [LeetCode]
The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- 10大html5前端框架
Bootstrap 首先说 Bootstrap,估计你也猜到会先说或者一定会有这个( 呵呵了 ),这是说明它的强大之处,拥有框架一壁江山的势气.自己刚入道的时候本着代码任何一个字母都得自己敲出来挡我者 ...
- while, do-while ,switch···case语句的学习与运用
1.while语句:当···的时候 格式:初始条件 while(循环条件) { 循环体; 状态改变; } 相当于 ...
- Eclipse中SVN的安装步骤(两种)和使用方法 [转]
一.给Eclipse安装SVN,最常见的有两种方式:手动方式和使用安装向导方式.具体步骤如下: 方式一:手动安装 1.从官网下载site-1.6.9.zip文件,网址是:subclipse.tigri ...