博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4597 Play Game
阅读量:4647 次
发布时间:2019-06-09

本文共 1338 字,大约阅读时间需要 4 分钟。

有两个双端队列每次每人可以从任意一堆的头或尾取值,两人均采取最优策略,问先手的最后得分

很简单的博弈

#include 
#include
#include
using namespace std;const int inf = 1000000000;int T, N, A[25], B[25], f[25][25][25][25];int DP(int a, int b, int c, int d) { int turn = N - (b - a + 1) + N - (d - c + 1); if(turn == (N << 1)) return 0; int & res = f[a][b][c][d]; if(res != -1) return res; if(turn & 1) { res = inf; if(a <= b) res = min(res, DP(a + 1, b, c, d)); if(a <= b) res = min(res, DP(a, b - 1, c, d)); if(c <= d) res = min(res, DP(a, b, c + 1, d)); if(c <= d) res = min(res, DP(a, b, c, d - 1)); } else { res = 0; if(a <= b) res = max(res, DP(a + 1, b, c, d) + A[a]); if(a <= b) res = max(res, DP(a, b - 1, c, d) + A[b]); if(c <= d) res = max(res, DP(a, b, c + 1, d) + B[c]); if(c <= d) res = max(res, DP(a, b, c, d - 1) + B[d]); } return res;}int main() { scanf("%d", &T); for(int kase = 1; kase <= T; kase++) { scanf("%d", &N); for(int i = 1; i <= N; i++) { scanf("%d", &A[i]); } for(int i = 1; i <= N; i++) { scanf("%d", &B[i]); } memset(f, -1, sizeof(f)); printf("%d\n", DP(1, N, 1, N)); } return 0;}

转载于:https://www.cnblogs.com/ljzalc1022/p/9064423.html

你可能感兴趣的文章
章三 链表
查看>>
Solution for Concurrent number of AOS' for this application exceeds the licensed number
查看>>
CSE 3100 Systems Programming
查看>>
IntelliJ IDEA 的Project structure说明
查看>>
Java Security(JCE基本概念)
查看>>
Linux Supervisor的安装与使用入门
查看>>
创建 PSO
查看>>
JasperReport报表设计4
查看>>
项目活动定义 概述
查看>>
团队冲刺04
查看>>
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>