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看成线段的两端, 问题就变成了,最多能选多少线段 使得不存在这样 ...
随机推荐
- Incorporating ASP.NET MVC and SQL Server Reporting Services, Part 1
Your ASP.NET MVC application needs reports. What do you do? In this article, I will demonstrate how ...
- WIN7系统操作快捷键
轻松访问 按住右Shift八秒钟:启用或关闭筛选键 按左 Alt+左 Shift+PrntScrn(或 PrntScrn):启用或关闭高对比度 按左 Alt+左 Shift+Num Lock :启用或 ...
- asp.net ajax 调用错误解决
ajax调用aspx页面出现如下错误 前台源代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- UI2_UITableViewDelete
// AppDelegate.m // UI2_UITableViewDelete // // Created by zhangxueming on 15/7/14. // Copyright (c) ...
- UI1_UITableViewHomeWork
// // AppDelegate.m // UI1_UITableViewHomeWork // // Created by zhangxueming on 15/7/14. // Copyrigh ...
- 基于python yield机制的异步操作同步化编程模型
又一个milestone即将结束,有了些许的时间总结研发过程中的点滴心得,今天总结下如何在编写python代码时对异步操作进行同步化模拟,从而提高代码的可读性和可扩展性. 游戏引擎一般都采用分布式框架 ...
- 10款让你心动的 HTML5 & CSS3 效果
这里集合的这组 HTML5 & CSS3 效果,有的是网站开发中常用的.实用的功能,有的是先进的 Web 技术的应用演示.不管哪一种,这些案例中的技术都值得我们去探究和学习. 1.超炫的 HT ...
- AndroidStudio中gradle异常:unexpected end of block data
原因:可能是Android buildTools版本不够高. 解决方法:打开build.gradle,将android中buildToolsVersion改为'20.0.0' (我使用的是gradle ...
- 在Java中怎样把数组转换为ArrayList?
翻译自:How to Convert Array to ArrayList in Java? 本文分析了Stack Overflow上最热门的的一个问题的答案,提问者获得了很多声望点,使得他得到了在S ...
- 使用C++读取UTF8及GBK系列的文本方法及原理
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4374404.html 1.读取UTF-8编码文本原理 首先了解UTF-8的编码方式,UTF- ...