Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp
题目链接:
http://codeforces.com/contest/378/problem/E
题意:
dota选英雄,现在有n个英雄,m个回合,两支队伍:
每一回合两个选择:
b 1,队伍一ban掉一个英雄,或是跳过这个回合
p 1,队伍1选一个英雄
现在每个队伍都是最优决策,问最后队伍一的英雄实力和-队伍二的英雄实力和。
题解:
状压dp,决策要倒过来做,也就是dp出后面回合的决策的基础上设计出对自己当前回合对自己最有利的决策。、
注意:只有top m的英雄有可能被选,其他的都不可能被选中。
dp[x]表示目前回合两支队伍的实力差。(其中每一位bit代表一个英雄,1说明英雄被ban或被p了,0表示该英雄还没有被选或被ban。
代码;
#include<iostream>
#include<utility>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn=<<;
const int INF=0x3f3f3f3f; int dp[maxn],op[],val[];
int n,m,team[]; inline int cnt_bit(int x){
return x==?:(x&)+cnt_bit(x>>);
} bool cmp(int a,int b){
return a>b;
} int main(){
scanf("%d",&n);
for(int i=;i<n;i++) scanf("%d",val+i);
sort(val,val+n,cmp);
scanf("%d",&m);
char s[];
for(int i=m;i>=;i--){
scanf("%s%d",s,&team[i]);
op[i]=(s[]=='p');
}
dp[]=;
for(int i=;i<(<<m);i++){
int cur=cnt_bit(i);
if(team[cur]==){
dp[i]=-INF;
for(int j=;j<m;j++){
if(i&(<<j)){
dp[i]=max(dp[i],dp[i^(<<j)]+op[cur]*val[j]);
}
}
}else{
dp[i]=INF;
for(int j=;j<m;j++){
if(i&(<<j)){
dp[i]=min(dp[i],dp[i^(<<j)]-op[cur]*val[j]);
}
}
}
}
printf("%d\n",dp[(<<m)-]);
return ;
}
Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp的更多相关文章
- Codeforces Round #222 (Div. 1) C. Captains Mode 状压
C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #222 (Div. 1) D. Developing Game 扫描线
D. Developing Game 题目连接: http://www.codeforces.com/contest/377/problem/D Description Pavel is going ...
- Codeforces Round #222 (Div. 1) B. Preparing for the Contest 二分+线段树
B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon ther ...
- Codeforces Round #222 (Div. 1) A. Maze dfs
A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid ...
- Codeforces Round #222 (Div. 1) Maze —— dfs(连通块)
题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然 ...
- Codeforces Round #222 (Div. 1) (ABCDE)
377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #inc ...
- Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
D. Developing Game Pavel is going to make a game of his dream. However, he knows that he can't mak ...
- Codeforces Round #222 (Div. 1) D. Developing Game
D - Developing Game 思路:我们先枚举左边界,把合法的都扣出来,那么对于这些合法的来说值有v 和 r两维了,把v, r看成线段的两端, 问题就变成了,最多能选多少线段 使得不存在这样 ...
随机推荐
- C# 操作 Excel 常见问题收集和整理(定期更新,欢迎交流)
经常会有项目需要把表格导出为 Excel 文件,或者是导入一份 Excel 来操作,那么如何在 C# 中操作 Excel 文件成了一个最基本的问题. 做开发这几年来,陆陆续续也接触过这样的需求,但因为 ...
- jQuery Ajax应用
jQuery Ajax应用 本章主要了解jQuery的Ajax与传统的Ajax的区别,掌握JQuery的Ajax常用的方法与Ajax相关的函数. 详细内容,请点击jQuery Ajax应用查看:
- FMS服务器在centos下安装
首先当然得先下载安装包了 http://pan.baidu.com/s/1jGL1Nvw #要先安装一下这个包,否则会提收提示错误,缺少libcap yum install compat-libcap ...
- byte[] 清空
1. using(byte buff = new byte[Size]){ // 你要用的代码,} 2. Array.Clear(bytes, 0 ,bytes.Length);
- HTML+CSS学习笔记 (10) - CSS格式化排版
文字排版--字体 我们可以使用css样式为网页中的文字设置字体.字号.颜色等样式属性.下面我们来看一个例子,下面代码实现:为网页中的文字设置字体为宋体. body{font-family:" ...
- HashSet和LinkedHashSet特点.
1)::HashSet-------(内部为HashCode表数据结构)---(保证数据唯一,但不保证数据有序) 不对数据进行排序,只是通过hashCode和equal对数据进行相同判定,如果相同就不 ...
- 洛谷 P3374 【模板】树状数组 1
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
- extern 数组
最近比较关注C++对象的Linkage类型,然后今天突然想起extern数组这个奇葩的东西,稍微折腾了一下,顺手写个随笔. 首先在cpp中定义几个数组: ,,,,}; ,,,,}; ,,,,}; 然后 ...
- 更新win7资源管理器
更新exeplorer.exe: 1.方法1: void RefreshExplorer() { ]; SHELLEXECUTEINFOA shellExeInfo={}; shellExeInfo. ...
- C++ 中的 const 详解
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4235721.html 1.为什么使用 const int 而不使用 #define 在使用# ...