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

#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. LR11安装和配置教程

    LoadRunner11安装教程 #安装包文件.汉化文件.破解文件,可以自行百科来获得,这边仅提供安装步骤. 1.前期准备1)安装前需要关闭防火墙及杀毒软件2)安装路径不能包含中文字符,同时需要以管理 ...

  2. 玄学C语言之scanf,printf

    #include <bits/stdc++.h> using namespace std; int main() { int a,c,d; ]; scanf("%d." ...

  3. Scala 的list

    9.1 使用列表 列表类型:跟数组一样,列表也是同质化的(homogeneous).即所有元素都要是同种类型. 列表结构:所有列表由两部分组成:Nil 和 ::(cons). 基本操作:主要有三个:h ...

  4. 基于Python的Web应用开发实战——2 程序的基本结构

    2.1 初始化 所有Flaks程序都必须创建一个程序实例. Web服务器使用一种名为Web服务器网关接口(Web Server Gateway Interface,WSGI)的协议,把接收自客户端的所 ...

  5. python常用模块之requests

    一.requests 1.GET   url带参数请求 >>> payload = {'key1': 'value1', 'key2': 'value2'} >>> ...

  6. 国庆集训 || Wannafly Day1

    网址:https://www.nowcoder.com/acm/contest/201#question A.签到 手速石头剪刀布 #include <cstdio> #include & ...

  7. SpringBoot入门,新建SpringBoot项目

    一.在Spring Initializr中创建初始化项目 https://start.spring.io/ 二.通过maven导入Idea中(解压后的项目) 解压文件 黄色的为项目需要的真正的代码 , ...

  8. shell脚本,一个经典题目。

    [root@localhost wyb]# cat zhuijiu.sh #!/bin/bash #.写一个脚本执行后,输入名字,产生随机数01-99之间的数字. #.如果相同的名字重复输入,抓到的数 ...

  9. base64类

    public class Base64{ /** * how we separate lines, e.g. \n, \r\n, \r etc. */ private String lineSepar ...

  10. Ubuntu创建应用快捷方式

    Ubuntu创建应用快捷方式 新建一个.desktop文件 vi eclipse.desktop 然后又进行编辑 [Desktop Entry] Encoding=UTF-8 Name=eclipse ...