Hdu 4597记忆化搜索
好久没有做题了,水平已经完全在学弟之下了。
一个吉林邀请赛最水的题目。:(
其实这题一看到数据范围,只可以想到思路,直接爆搜,加个记忆化。
这题虽然A了,但是我还是没太想清楚一些边界情况,心虚着A了。
我的代码如下:
/*************************************************************************
> File Name: 4597.c
> Author: Stomach_ache
> Mail: 1179998621@qq.com
> Created Time: 2014年03月02日 星期日 13时04分27秒
> Propose:
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h> #define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y)) int a[], b[], dp[][][][], n, t;
int sum_a[], sum_b[]; int
dfs(int f1, int e1, int f2, int e2) { if (dp[f1][e1][f2][e2] != -)
return dp[f1][e1][f2][e2];
if (f1 > e1 && f2 > e2)
return dp[f1][e1][f2][e2] = ; int res = , sum = ;
if (f1 <= e1) sum += sum_a[e1] - sum_a[f1-];
if (f2 <= e2) sum += sum_b[e2] - sum_b[f2-]; if (f1 <= e1) {
res = max(res, sum - dfs(f1+, e1, f2, e2));
res = max(res, sum - dfs(f1, e1-, f2, e2));
}
if (f2 <= e2) {
res = max(res, sum - dfs(f1, e1, f2+, e2));
res = max(res, sum - dfs(f1, e1, f2, e2-));
} return dp[f1][e1][f2][e2] = res;
} int
main(void) { scanf("%d", &t);
while ( t-- ) {
scanf("%d", &n);
int i;
sum_a[] = sum_b[] = ;
for (i = ; i <= n; i++) {
scanf("%d", a+i);
sum_a[i] = sum_a[i-]+a[i];
}
for (i = ; i <= n; i++) {
scanf("%d", b+i);
sum_b[i] = sum_b[i-]+b[i];
} memset(dp, -, sizeof(dp));
printf("%d\n", dfs(, n, , n));
} return ;
}
Hdu 4597记忆化搜索的更多相关文章
- HDU 4597 记忆化搜索
² 博弈取牌—记忆化搜索 题目描述: 有两副带有数字的牌,(数字>0)两人轮流取,取中了某张牌,自己的分数就加上牌上的数字,但只能从两端取,每人都会用最优的策略使得自己的分数最高.问A先取,他能 ...
- hdu 4722(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4722 思路:简单的记忆化搜索,留意一下A==0时的情况就可以了. #include<iostre ...
- hdu 1514 记忆化搜索
题意是给4堆(堆的高度小于等于40)有颜色(颜色的种类小于等于20)的物品,你有一个篮子最多能装5件物品,每次从这4堆物品里面任取一件物品放进篮子里,但是取每堆物品时,必须先取上面的物品,才能取下面的 ...
- hdu 1208 记忆化搜索
题目大意:只能按照格子上的数字*方向走,从左上走到右下Sample Input42331121312313110Sample Output3 直接记忆化搜索,注意是0的情况 #include<c ...
- hdu 4960 记忆化搜索 DP
Another OCD Patient Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Ot ...
- hdu 2089 记忆化搜索写法(数位dp)
/* 记忆化搜索,第二维判断是否是6 */ #include<stdio.h> #include<string.h> #define N 9 int dp[N][2],digi ...
- HDU 1978 记忆化搜索(dfs+dp)
Y - How many ways Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- hdu 1078(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 //dp[i][j]表示从点i,j处开始能获得的最多cheese #include <io ...
- hdu 1978 记忆化搜索
注意: dp[i][j] 表示(i,j)这个点有多少种方式 mark[i][j]表示这个点是否走过 假设有直接返回dp[i][j] dp的求法为全部梦走到点的dp的和 注意mark ...
随机推荐
- HZOI20190823模拟31题解
题面:https://www.cnblogs.com/Juve/articles/11425141.html math:仔细看看其实是个水题 #include<iostream> #inc ...
- dubbo入门学习(五)-----dubbo的高可用
zookeeper宕机与dubbo直连 现象 zookeeper注册中心宕机,还可以消费dubbo暴露的服务. 原因 健壮性 l 监控中心宕掉不影响使用,只是丢失部分采样数据 l 数据库宕掉后,注册中 ...
- Python导出DBF文件到Excel的方法
Python导出DBF文件到Excel的方法 这篇文章主要介绍了Python导出DBF文件到Excel的方法,实例分析了Python基于win32com模块实现文件导出与转换的相关技巧,分享给大家供大 ...
- MySQL用户权限详细汇总
1,MySQL权限体系 mysql 的权限体系大致分为5个层级:全局层级:全局权限适用于一个给定服务器中的所有数据库.这些权限存储在mysql.user表中.GRANT ALL ON .和REVOKE ...
- Leetcode106. Construct Binary Tree from Inorder and Postorder Traversal中序后续构造二叉树
根据一棵树的中序遍历与后序遍历构造二叉树. 注意: 你可以假设树中没有重复的元素. 例如,给出 中序遍历 inorder = [9,3,15,20,7] 后序遍历 postorder = [9,15, ...
- 设置mysql二进制日志过期时间
((none)) > show variables like 'expire_logs_days'; +------------------+-------+ | Variable_name | ...
- Ubuntu 链接ln的使用:创建和删除符号链接
一 . 使用方式 ln [option] source_file dist_file (source_file是待建立链接文件的文件,dist_file是新创建的链接文件) -f 建立时,将同档案名删 ...
- sulin LuceneNet 搜索二
1.添加引用dll using Lucene.Net.Search;using Lucene.Net.Analysis.PanGu;using PanGu;using PanGu.HighLight; ...
- PhpExcel参考网址
参考网址: http://www.cnblogs.com/yuwensong/p/3771787.html
- 前端插件--swipe.js
swipe.js的作用: 这是一个轻量级的移动滑动组件,支持触摸移动,支持响应式页面. 效果图: 代码: <!DOCTYPE html> <html lang="en&qu ...