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

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

思路

  • 开始没读懂题,也没注意看数据范围(1000*200的状态,记忆化搜索随便搞)
  • 用记忆化搜索处理出来每个状态的胜负情况
  • 因为每个人都会选择最优的,因此记忆化搜索的过程其实就是在模拟两个人每一步决策所带来的胜负情况,

    只要返回一个必胜,就直接返回(因为会选择最优)

    然后在没有返回必胜的状态下,有平局就选择平局,没有平局就只能输了

#include<bits/stdc++.h>
#define st 100
#define M 1005
using namespace std;
int f[M][500],n,m,l,r,a[M],b[M],c[M],ret,i;
int dfs(int d,int p){
   if(d==n){
      if(p<=l)return 4;else if(p>=r)return 1;else return 2;
   }
   int &ans=f[d][p+st];
   if(ans!=-1)return ans;
   int win,los,ok=0,tp;
   if(d&1){win=4;los=1;}else{win=1;los=4;}
   if(a[d]){
      tp=dfs(d+1,min(100,p+a[d]));
      if(tp==win)return ans=win;
      if(tp==2) ok=1;
   }
   if(b[d]){
      tp=dfs(d+1,max(-100,p-b[d]));
      if(tp==win)return ans=win;
      if(tp==2)ok=1;
   }
   if(c[d]){
      tp=dfs(d+1,-p);
      if(tp==win)return ans=win;
      if(tp==2)ok=1;
   }
   if(ok)return ans=2;
   return ans=los;
}
int main(){
   memset(f,-1,sizeof(f));
   scanf("%d%d%d%d",&n,&m,&r,&l);
   for(i=0;i<n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
   ret=dfs(0,m);
   if(ret==1)cout<<"Good Ending"<<endl;
   else if(ret==4)cout<<"Bad Ending"<<endl;
   else cout<<"Normal Ending"<<endl;
}

知识点

  • dp数组储存胜负状态(记忆化搜索,博弈)

原文地址:https://www.cnblogs.com/VIrtu0s0/p/9623614.html

时间: 2024-08-09 08:53:02

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

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

In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named "Sena" are playing a video game. The game system of this video game is quite unique: in the process of playing this game, you need to constantly fac

ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE &lt;&lt;DP

题意 两个人在一起玩galgame,一个人想看good ending,另一个想看bad ending,两个人轮流选选项都按最优策略选,问最后能看到什么结局. 思路 可以理解为一个人想让最终分数尽可能高,另一个想让最终分数尽可能低,然后根据每个问题双向dp,一下子就写出来了. 代码 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1005; 4 struct selection{ 5 int a,b,c; 6 }; 7

ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath

ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath 做法: \[f(m,n) = \sum _{i=1}^{m} \mu(in) = \sum_{i=1}^{m}[gcd(i,n)=1]\mu(i)\mu(n) = \mu(n)\sum_{d|n}\mu(d)f(\frac{m}{d},d)\] 边界: n=1,杜教筛求\(\sum_{i=1}^{m}\mu(i)\),m = 1, 返回\(\mu(n)\),预处理尽可能把空间卡满. 2个小时的时候就推出来了这个式子,不会算复杂

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn&#39;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 learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he wi

ACM-ICPC 2018 徐州赛区网络预赛 H. Ryuji doesn&#39;t want to study (线段树)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a

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

ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer master has to do his job. A tour company gives him a map which is a rectangle. The map consists of N \times MN×M little squares. That is to say, the h

ICPC 2018 徐州赛区网络赛

ACM-ICPC 2018 徐州赛区网络赛 ?去年博客记录过这场比赛经历:该死的水题 ?一年过去了,不被水题卡了,但难题也没多做几道.水平微微有点长进. ? ? D. Easy Math 题意: ? 给定 \(n\), \(m\) ,求 \(\sum _{i=1}^{m} \mu(in)\) .其中 $ 1 \le n \le 1e12$ , $ 1 \le m \le 2e9$ ,\(\mu(n)\) 为莫比乌斯函数. ? 思路: ? 容易知道,\(i\) 与 \(n\) 不互质时, \(\m

ACM-ICPC 2018 徐州赛区网络预赛

Rank Solved A B C D E F G H I J K 157/1526 7/11 O O ? ? . O O O O O ? O: 当场通过 ?: 赛后通过 .: 尚未通过 A Hard to prepare solved by chelly chelly's solution B BE, GE or NE solved by ch ch's solution C Cacti Lottery upsolved by chelly chelly's solution 考虑枚举*代表的

ACM-ICPC 2018 徐州赛区网络预赛 A. Hard to prepare

传送门:https://nanti.jisuanke.com/t/31453 本题是一个组合数学(DP,滑稽)题. 一个环上有N个位置,标号为1~N.设第i(1≤i≤N)个位置上的数为x[i],限制条件为:0≤x[i]<2k.另有限制条件:当位置i和位置j相邻时,x[i]⊕x[j]≠2k-1.求满足限制条件的环的状态数. 可以考虑将环切割成链,以分析问题.设: ①a[n]:长度为n,且首尾相同的满足上述条件的链的状态数: ②b[n]:长度为n,且首尾相反的满足上述条件的链的状态数: ③c[n]: