ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE <<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 selection option[N];
 8 int dp[N][205];
 9 int n,m,k,l;
10 int dfs(int now,int score)
11 {
12     if(now==n+1) return score;
13     if(dp[now][score]!=-1) return dp[now][score];
14     selection &nn=option[now];
15     if(now%2!=0){
16         int ret=-1;
17         if(option[now].a)
18             ret=max(dfs(now+1,score+nn.a>200?200:score+nn.a),ret);
19         if(option[now].b)
20             ret=max(dfs(now+1,score-nn.b<0?0:score-nn.b),ret);
21         if(option[now].c)
22             ret=max(dfs(now+1,200-score),ret);
23         dp[now][score]=ret;
24     }
25     else{
26         int ret=300;
27         if(option[now].a)
28             ret=min(dfs(now+1,score+nn.a>200?200:score+nn.a),ret);
29         if(option[now].b)
30             ret=min(dfs(now+1,score-nn.b<0?0:score-nn.b),ret);
31         if(option[now].c)
32             ret=min(dfs(now+1,200-score),ret);
33         dp[now][score]=ret;
34     }
35     return dp[now][score];
36 }
37 int main()
38 {
39     scanf("%d%d%d%d",&n,&m,&k,&l);
40     for(int i=1,a,b,c;i<=n;i++)
41     {
42         scanf("%d%d%d",&a,&b,&c);
43         option[i]={a,b,c};
44     }
45     memset(dp,-1,sizeof(dp));
46     int ans=dfs(1,m+100);
47     if(ans>=k+100) printf("Good Ending\n");
48     else if(ans>l+100) printf("Normal Ending\n");
49     else printf("Bad Ending\n");
50     return 0;
51 }

后记

这题赛时没想出来,一开始觉得是博弈,后来想了想隐隐感觉是dp,但是没下手做,丢给了不会dp的楼教主,然后这题就没了,把时间都花别的地方去了,以后还是应该听从榜的召唤跟一下榜。

原文地址:https://www.cnblogs.com/computer-luo/p/9630904.html

时间: 2024-11-10 00:32:21

ACM-ICPC 2018 徐州赛区网络预赛 B. BE, GE or NE <<DP的相关文章

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(博弈,记忆化搜索)

链接https://nanti.jisuanke.com/t/31454 思路 开始没读懂题,也没注意看数据范围(1000*200的状态,记忆化搜索随便搞) 用记忆化搜索处理出来每个状态的胜负情况 因为每个人都会选择最优的,因此记忆化搜索的过程其实就是在模拟两个人每一步决策所带来的胜负情况, 只要返回一个必胜,就直接返回(因为会选择最优) 然后在没有返回必胜的状态下,有平局就选择平局,没有平局就只能输了 #include<bits/stdc++.h> #define st 100 #defin

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]: