传送门:CF

题目描述:

outputstandard output
Bobo has recently learned how to play Dota2. In Dota2 competitions, the mechanism of banning/picking
heroes is introduced, modified and simplified as follows for the sake of the problem:
Suppose a game is played between two teams: Team A and Team B. Each team has a hero pool of n
heroes with positive utility scores a1,…,an and b1,…,bn, respectively. Here we assume all heroes in two
teams' hero pool are distinct.
The two teams then perform ban/pick operations alternately, with Team A going first. In one team's turn, it
can either pick a hero for itself, or ban an unselected hero from the opponent's hero pool.
After 2n turns, all heroes are either picked or banned. Each team then needs to choose at most k heroes
from all heroes it picked to form a warband and the score for the warband is calculated as the sum of
utility scores over all heroes in it.
Let sA,sB be the score of the warband formed by Team A and Team B, respectively. Team A wants to
maximize the value of sA−sB while Team B wants to minimize it.
Bobo wants to know, what should be the final value of sA−sB, if both teams act optimally? He's not really
good at calculating this, so he turned to you for help.
输入:
2 1
3 6
2 4
输出:
2

一道博弈论dp的题目,比赛的时候推出了dp方程,转移也想出来了,但是不知道博弈论dp正推会有后效性,需要逆推,所以VP的时候打出来正推的dp,然后就…,感觉主要问题在于之前我对于博弈论并不是很重视,以至于这方面的题目基本没打过,是空白的,所以造成了连博弈论dp都没看出来这个大问题,赛后赶紧补几道

对于这道题,我们观察一下题目,会发现 n n n的范围超过了1e5,但是 k k k的范围只有10.所以我们的解法肯定是和 k k k有关系的,然后赛场上我想到了dp.dp应该也不难想,大概就是 d p [ i ] [ j ] [ j 2 ] dp[i][j][j2] dp[i][j][j2]记录前 i i i轮操作(每轮操作可以进行禁和选)A方选择了 j j j个英雄,B方选择了 j 2 j2 j2个英雄的最优策略.但是打完会发现这样是不行的,因为我们之前选择的方式会影响后面的决策,所以正确的写法是倒推

我们将我们的dp方程改一下,将 d p [ i ] [ j ] [ j 2 ] dp[i][j][j2] dp[i][j][j2]改成经过前 i i i轮A方选择了 j j j个英雄,B方选择了 j 2 j2 j2个英雄之后 2 ∗ n − i 2*n-i 2∗n−i轮所有情况的最优策略,此时我们将dp方程的影响范围从前面改到了后面.这样的话,我们就会发现现在后面的策略选择并不会影响前面的了,此时就符合了dp的无后效性.那么转移方程也就不难写出了

对于当前 d p [ i ] [ n u m a ] [ n u m b ] dp[i][numa][numb] dp[i][numa][numb]来说,如果当前是A进行选择,有两种情况:
1.A选择英雄,那么此时 d p [ i ] [ n u m a ] [ n u m b ] = d p [ i + 1 ] [ n u m a + 1 ] [ n u m b ] + a [ n o w a ] dp[i][numa][numb]=dp[i+1][numa+1][numb]+a[nowa] dp[i][numa][numb]=dp[i+1][numa+1][numb]+a[nowa]
其中我们的 n o w a nowa nowa是当前A所有英雄中除了被禁和选之外最大的数字,nowa不难求出
2.A选择禁英雄.那么此时 d p [ i ] [ n u m a ] [ n u m b ] = d p [ i + 1 ] [ n u m a ] [ n u m b ] dp[i][numa][numb]=dp[i+1][numa][numb] dp[i][numa][numb]=dp[i+1][numa][numb]
因为A的策略是尽量大,所以此时我们两者取max即可

如果当前是B进行选择,也有两种情况:
1.B选择英雄,那么此时 d p [ i ] [ n u m a ] [ n u m b ] = d p [ i + 1 ] [ n u m a ] [ n u m b + 1 ] − b [ n o w b ] dp[i][numa][numb]=dp[i+1][numa][numb+1]-b[nowb] dp[i][numa][numb]=dp[i+1][numa][numb+1]−b[nowb]
其中 n o w b nowb nowb的定义和 n o w a nowa nowa相同
2.B选择禁英雄,那么此时 d p [ i ] [ n u m a ] [ n u m b ] = d p [ i + 1 ] [ n u m a ] [ n u m b ] dp[i][numa][numb]=dp[i+1][numa][numb] dp[i][numa][numb]=dp[i+1][numa][numb]
因为B的策略是尽量小,所以此时我们两者取min即可

对于这种倒推形dp,记忆化搜索往往比直接dp来的舒服


下面是具体的代码部分:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {ll x=0,w=1;char ch=getchar();for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';return x*w;
}
#define maxn 1000000
const double eps=1e-8;
#define int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
int n,k;
int a[maxn];int b[maxn];
bool cmp(int aa,int bb) {return aa>bb;
}
int dp[200010][12][12];int vis[200010][12][12];
int solve(int step,int numa,int numb) {if(step>2*n) return 0;if(vis[step][numa][numb]) return dp[step][numa][numb];vis[step][numa][numb]=1;if(step&1) {int nowa=((step-1)/2-numb)+numa+1;dp[step][numa][numb]=solve(step+1,numa,numb);if(nowa<=n&&numa<k) dp[step][numa][numb]=max(dp[step][numa][numb],solve(step+1,numa+1,numb)+a[nowa]);return dp[step][numa][numb];}else {int nowb=(step/2-numa)+numb+1;dp[step][numa][numb]=solve(step+1,numa,numb);if(nowb<=n&&numb<k) dp[step][numa][numb]=min(dp[step][numa][numb],solve(step+1,numa,numb+1)-b[nowb]);return dp[step][numa][numb];}
}
int main() {n=read();k=read();for(int i=1;i<=n;i++) a[i]=read();for(int i=1;i<=n;i++) b[i]=read();sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp);solve(1,0,0);cout<<dp[1][0][0]<<endl;return 0;
}

赛后补题:2022CCPC绵阳 A. Ban or Pick, What‘s the Trick相关推荐

  1. Codeforces Round #701 (Div. 2)赛后补题报告(A~D)

    Codeforces Round #701 (Div. 2)赛后补题报告(A~D) A. Add and Divide 原题信息 http://codeforces.com/contest/1485/ ...

  2. 2021年度训练联盟热身训练赛第三场赛后补题

    2021年度训练联盟热身训练赛第三场赛后补题 A Circuit Math [题目分析] [代码展示] B Diagonal Cut [题目分析] [代码展示] C Gerrymandering [题 ...

  3. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  4. 2020年湖南中医药大学“华为杯”大学生程序设计竞赛——正式赛(赛后补题)

    目录 A-幸福小组 B-菜鸡驿站 C-TC的火柴 D-n盏灯 E-电子手表 F- TC的steam账号 G- 万圣节 H-最少颜色 I-2048 J-解密 K-TC的门牌号 L-粗心的小明 M-小明的 ...

  5. coderforce Educational Codeforces Round 44 (Rated for Div. 2) C(赛后补题)

    C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. 2020年湖南中医药大学“华为杯”大学生程序设计竞赛(赛后补题)

    这次院赛给打自闭了,从头到尾一直落在后面,最后只拿到了二等奖尾,还是太菜了,唉(难受).多刷题!!! (未完待续) 目录 A:幸福小组 B:菜鸟驿站 C:TC的火柴 D:n盏灯 E:电子手表 F:TC ...

  7. HDU 6446 Tree and Permutation(赛后补题)

    >>传送门<< 分析:这个题是结束之后和老师他们讨论出来的,很神奇:刚写的时候一直没有注意到这个是一个树这个条件:和老师讨论出来的思路是,任意两个结点出现的次数是(n-1)!, ...

  8. Codeforces Round #498 (Div. 3) - 赛后补题

    D. Two Strings Swaps PS:没思考清楚,重复算了一些情况. #include<bits/stdc++.h> #include<bitset> #define ...

  9. (赛后补题)Gym - 101020 H H - Weekend

    今天模拟赛我给忘了,睡过了......来的时候已经过了一个小时了,然后就没做到这个题,其实特别简单. ou and your friends are going to camping next wee ...

最新文章

  1. PTA数据结构与算法题目集(中文)7-15
  2. 一处 ADO.NET Entity Framework 的逻辑BUG
  3. Python使用you-get批量下载bilibili网站视频
  4. 从工作中清除代码–使用JUnit 5,Mockito和AssertJ编写可执行规范
  5. inline「一」:从 image 底部白边初识 line-height
  6. docker 报错 Container is not running
  7. python 生成 和 加载 requirements.txt
  8. 【Tensorflow】深度学习实战01——Tensorflow实现简单的卷积网络(MNIST)
  9. (32)System Verilog类class中构造函数new()示例
  10. 小白成长建议(9)-苞丁解牛
  11. JAVA中的“抽象接口”
  12. Abseil之string_view
  13. 显示纯服务器_BBT三行代码搭建服务器,让Dynamo跳出IronPython的封锁
  14. 100-网络编程——第五章流式套接字
  15. 修改Tomcat8 内存
  16. 【软考中级】多媒体基础知识整理(个人整理)
  17. excel图表交互联动_office2016下PPT图表进行交互联动的技巧
  18. 计算机打不开网络邻居,打不开网上邻居的电脑是怎么回事
  19. 斯坦福大学公开课:量子力学
  20. 超级账本执行董事:区块链将削弱谷歌、亚马逊和Facebook的市场力量

热门文章

  1. 主梁弹性模量计算_4主梁作用效应计算-金锄头文库
  2. 使用 Sa-Token 解决 WebSocket 握手身份认证
  3. 【CAD二次开发】-ObjectARX-扩展数据 (Xdata)
  4. 内推 | 数据开发——江小白
  5. 常见的网页播放器代码
  6. 谈谈赚钱的套路 - 消费冲动与消费信心。
  7. 思科(Netacad)账号注册教学,完美解决登录时找不到该账号的问题,亲身实测可用。最新最详细
  8. 唾手可得WeMall一元购源代码
  9. gridview的sort_Gridview分页后排序
  10. ubuntu18.04 安装HP打印机