https://nanti.jisuanke.com/t/31454

题意

两个人玩游戏,最初数字为m,有n轮,每轮三个操作给出a b c,a>0表示可以让当前数字加上a,b>0表示可以让当前数字减去b,c=1表示可以让当前数字乘-1,数字范围为[-100, 100],如果加/减出范围则直接等于边界,最终结果数字x>=R则为Good Ending,x<=L则为Bad Ending,否则Normal Ending,第一个人希望好结局,第二个人希望坏结局,如果没有办法就希望平局,每个人都做最优选择。求最终结果

分析

一开始题目没看懂啊。。很蒙,然后学弟就秒了。

所以状态1000*200,考虑暴力求解。又是博弈题,那当然是记忆化搜索啦。把每个状态都搜一下,优先选赢,其次才是平局,最后才是输。

因为分数可能为负数,所以这里加了个115变成正数来计算,方便得多。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mod 1000000007
int n, L, R, dp[][];
typedef struct Res{
int x, y, z;
}Res;
Res s[];
int Go(int x, int y, int t=){
if(x==) y = min(y+t, );
else if(x==) y = max(y-t, );
else y += *(-y);
return y;
}
int dfs(int id, int x){
int win, lose, done, temp;
if(dp[id][x]<=)
return dp[id][x];
if(id==n+){
if(x>=R) return ;
if(x<=L) return -;
return ;
}
win = lose = done = ;
if(id%){//先手,想造出GoodEnding
if(s[id].x!=){
temp = dfs(id+, Go(, x, s[id].x));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(s[id].y!=){
temp = dfs(id+, Go(, x, s[id].y));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(s[id].z!=){
temp = dfs(id+, Go(, x));
if(temp==) win = ;
if(temp==) done = ;
if(temp==-) lose = ;
}
if(win) return dp[id][x] = ;
else if(done) return dp[id][x] = ;
else return dp[id][x] = -;
}else{
if(s[id].x!=){
temp = dfs(id+, Go(, x, s[id].x));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(s[id].y!=){
temp = dfs(id+, Go(, x, s[id].y));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(s[id].z!=){
temp = dfs(id+, Go(, x));
if(temp==) lose = ;
if(temp==) done = ;
if(temp==-) win = ;
}
if(win) return dp[id][x] = -;
else if(done) return dp[id][x] = ;
else return dp[id][x] = ;
}
}
int main(){
int ans, m, i;
scanf("%d%d%d%d", &n, &m, &R, &L);
R += , L += ;
for(i=;i<=n;i++)
scanf("%d%d%d", &s[i].x, &s[i].y, &s[i].z);
memset(dp, , sizeof(dp));
ans = dfs(, m+);
if(ans==) puts("Good Ending");
else if(ans==-) puts("Bad Ending");
else puts("Normal Ending");
return ;
}

ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(记忆化搜索)的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE(博弈,记忆化搜索)

    链接https://nanti.jisuanke.com/t/31454 思路 开始没读懂题,也没注意看数据范围(1000*200的状态,记忆化搜索随便搞) 用记忆化搜索处理出来每个状态的胜负情况 因 ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 B BE, GE or NE 【模拟+博弈】

    题目:戳这里 题意:A和B博弈,三种操作分别是x:加a,y:减b,z:取相反数.当x或y或z为0,说明该操作不可取,数据保证至少有一个操作可取,给定一个区间(l,k)和原始数字m,如果A和B在n次操作 ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  6. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

  8. ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn't want to study

    262144K   Ryuji is not a good student, and he doesn't want to study. But there are n books he should ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 F. Features Track

    262144K   Morgana is learning computer vision, and he likes cats, too. One day he wants to find the ...

随机推荐

  1. codeforces/contest/803/problem C

    题目:C. Maximal GCD 题意:输入n,k.将n拆成k个数的序列,使得这k个数的gcd最大.(且序列严格递增).1 ≤ n, k ≤ 1010 . 分析:假设k个数的gcd为d,则一定有d| ...

  2. 关于clone(java.lang.Object)重写

    1. 需要实现接口java.lang.Cloneable 2. 重写java.lang.Object的clone 3. clone访问权限扩大为public 4. 不实现(java.lang.Clon ...

  3. 闭包函数&回调函数

    闭包函数&回调函数 谈到回调函数,不得不提匿名函数;匿名函数,也叫闭包函数,也就是没有名字的函数,它可以单独存在,也可以将其赋值给某一个变量.so,先来看一下闭包函数. 闭包函数 php文档: ...

  4. Sublime3如何用快捷键实现字母的大小写转换

    说明 有的时候需要将字母大小写一键转换一下,很显然,通过编辑器来实现会更加轻量级,而不是打开IDE去实现 我用的Sublime3版本如下: 步骤 1.打开Sublime的Key Bindings 2. ...

  5. Scheme来实现八皇后问题(1)

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/9768105.html 作者:窗户 Q ...

  6. hmac_检验客户端是否合法

    老师博客:http://www.cnblogs.com/Eva-J/articles/8244551.html#_label6 server端 import socket import os impo ...

  7. vue 组件开发、vue自动化工具、axios使用与router的使用(3)

    一. 组件化开发 1.1 组件[component] 在网页中实现一个功能,需要使用html定义功能的内容结构,使用css声明功能的外观样式,还要使用js定义功能的特效,因此就产生了一个功能先关的代码 ...

  8. leetcode 169. Majority Element 、229. Majority Element II

    169. Majority Element 求超过数组个数一半的数 可以使用hash解决,时间复杂度为O(n),但空间复杂度也为O(n) class Solution { public: int ma ...

  9. Autoware(2)—加载地图数据

    选择Point cloud.Ref选择.autoware/.data/map/pointcloud_map/里面的全选 点Point cloud加载 vector Map和TF同理

  10. 使用Fabric Node SDK进行Invoke和Query

    前面的文章都是在讲解Fabric网络的搭建和ChainCode的开发,那么在ChainCode开发完毕后,我们就需要使用Fabric SDK做应用程序的开发了.官方虽然提供了Node.JS,Java, ...