博弈论极小极大搜索,记忆化+状压

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=2e4+;
const int inf=;
int a[];
int three[];
int tmp[];
int ans[maxn][];
void pre(){
three[]=;
for(int i=;i<;i++){
three[i]=three[i-]*;
}
}
int judge(vector<int> tmp){
int res=;
for(int i=;i<;i++){
res+=(tmp[i]==);
}
//ALice
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return res+;
}
//Bob
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
if(tmp[]==&&tmp[]==&&tmp[]==){
return -(res+);
}
//Tie
if(res==) return ;
//None
return inf; } int dfs(int s,int p){
if(ans[s][p]!=inf) return ans[s][p];
vector<int> tmp;
for(int i=;i<;i++) tmp.push_back();
int ss=s;
int cnt=;
while(ss){
tmp[cnt]=ss%;
ss/=;
cnt++;
}
int x=judge(tmp);
if(x!=inf) return ans[s][p]=x;
if(p==){
int res=-inf;
for(int i=;i<;i++){
if(tmp[i]==){
res=max(res,dfs(s+*three[i],));
}
}
return ans[s][p]=res;
}else{
int res=inf;
for(int i=;i<;i++){
if(tmp[i]==){
res=min(res,dfs(s+*three[i],));
}
}
return ans[s][p]=res;
}
}
int main(){
int T;
scanf("%d",&T);
pre();
while(T--){
for(int i=;i<maxn;i++){
ans[i][]=ans[i][]=inf;
}
for(int i=;i<;i++) scanf("%d",&a[i]);
int s=;
for(int i=;i<;i++){
s+=a[i]*three[i];
}
int ans=dfs(s,);
printf("%d\n",ans);
}
return ;
}

【CCF】棋局评估的更多相关文章

  1. ccf 201803-4 棋局评估(Python实现)

    一.原题 问题描述 试题编号: 201803-4 试题名称: 棋局评估 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很 ...

  2. ccf 201803-4 棋局评估 (对抗搜索)

    棋局评估 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很简单:两人轮流往3*3的棋盘中放棋子,Alice放的是“X”,Bob放的是“O”,Alice执先.当同一种棋子占据一行.一列 ...

  3. CCF(棋局评估)博弈论+对抗搜索+DFS

    201803-4 棋局评估 这题主要使用对抗搜索,也就是每一步寻找可以下棋的位置,通过在这一步下棋看最后会取的什么样的分数. #include<iostream> #include< ...

  4. CCF-CSP题解 201803-4 棋局评估

    求当前井字棋局的得分. 用dfs虚构一下搜索树,每个节点对应一个不同的棋局. 每个节点有一个situation()情况评估,若胜负已定,则对应该棋局的评分:否则为0,表示胜负未定或平局. 每个节点还有 ...

  5. CSP201803-4棋局评估

    问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很简单:两人轮流往3*3的棋盘中放棋子,Alice放的是“X”,Bob放的是“O”,Alice执先.当同一种棋子占据一行.一列或一条对角 ...

  6. 为何谷歌围棋AI AlphaGo可能会把李世石击溃

    /* 版权声明:可以随意转载,转载时请标明文章原始出处和作者信息 .*/ author: 张俊林 谷歌DeepMind开发的人工智能围棋程序AlphaGo以5:0的压倒性优势击败了欧洲围棋冠军.专业二 ...

  7. AlphaGo论文的译文,用深度神经网络和树搜索征服围棋:Mastering the game of Go with deep neural networks and tree search

    转载请声明 http://blog.csdn.net/u013390476/article/details/50925347 前言: 围棋的英文是 the game of Go,标题翻译为:<用 ...

  8. 机器学习系列(8)_读《Nature》论文,看AlphaGo养成

    作者:viewmode=contents">龙心尘 && viewmode=contents">寒小阳 时间:2016年3月. 出处:http://bl ...

  9. python 2048游戏控制器

    2048游戏控制器 1 evaluate 要用程序来处理就得对现实的问题进行量化,用数字来表示.在2048游戏中,我们的输入是一个棋局,让我们输出一个移动方向,这样我们需要对棋局进行量化,即我们要评估 ...

随机推荐

  1. CSS-学习笔记五

    1.  权重: 内联:A ID:B Class:C 标签:D 继承:0 2.  文字阴影text-shadow 3.  文字缩进text-index 4.  文本换行 5.  文本溢出 6.  圆角 ...

  2. 增加和减少mongodb复制集中的节点

    MongoDB Replica Sets不仅提供高可用性的解决方案,同时也提供负载均衡的解决方案,增减 Replica Sets节点在实际应用中非常普通.例如,当应用的读压力暴增时,3台节点的环境已不 ...

  3. 贴一发STL源码

    int my_lower_bound(int size, long long key){    int first = 0, middle;    int half, len;    len = si ...

  4. C++数据文件存储与加载(利用opencv)

    首先请先确认已经安装好了opencv3及以上版本. #include <opencv2/opencv.hpp>#include <iostream>#include <s ...

  5. 并查集+思维——X-Plosives

    一.问题描述(题目链接) 有n种化合物,每种化合物由两种元素组成.当几种的化合物数量等于他们所含不同元素的数量时,就会发生爆炸.现在依次给出化合物的组成,当新的化合物与之前的化合物放在一起会发生爆炸时 ...

  6. Mac电脑怎么显示隐藏文件、xcode清除缓存

    1.删除Xcode中多余的证书provisioning profile 手动删除: Xcode6 provisioning profile path: ~/Library/MobileDevice/P ...

  7. 译文 编写一个loader

    https://doc.webpack-china.org/contribute/writing-a-loader loader是一个导出了函数的node模块,当资源须要被这个loader所转换的时候 ...

  8. 二段式fsm

    1.推荐在敏感表下的默认状态为X,这样描述的好处有2个: 好处1:仿真易观察bug. 好处2:综合对不定态X的处理是"Don't Care",即任何没有定义的状态寄存器向量都会被忽 ...

  9. 【php】 布尔值判断

    当转换为 boolean 时,以下值被认为是 FALSE: 布尔值 FALSE 本身 整型值 0(零) 浮点型值 0.0(零) 空字符串,以及字符串 "0" 不包括任何元素的数组 ...

  10. (转)python之禅

    凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分 ...