Codeforces Round #222 (Div. 1) 博弈 + dp
一般这种要倒着来。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 1e5 + ;
const int M = 1e7 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int n, m, cur, x, up, a[N], f[][ << ], op[], cnt[ << ];
char t[][]; int dp(int x, int s) {
if(s == up - ) return ;
if(f[x][s] != inf) return f[x][s];
f[x][s] = op[x] == ? -inf : inf;
for(int j = ; j < n; j++) {
if((s >> j) & ) continue;
int add = t[x][] == 'p' ? a[j] : ;
if(op[x] == ) f[x][s] = max(f[x][s], dp(x + , s | ( << j)) + add);
else f[x][s] = min(f[x][s], dp(x + , s | ( << j)) - add);
}
return f[x][s];
} int main() {
memset(f, inf, sizeof(f));
scanf("%d", &n);
for(int i = ; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n); reverse(a, a + n);
scanf("%d", &m); n = min(n, m); up = << n; for(int i = ; i < m; i++)
scanf("%s%d", t[i], &op[i]); printf("%d\n", dp(, ));
return ;
} /*
*/
Codeforces Round #222 (Div. 1) 博弈 + dp的更多相关文章
- Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp
题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ba ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
- 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 #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
随机推荐
- 「Django」数据库访问优化
先做性能分析 - 两个工具 django.db.connection from django.db import connection# contextprint connection.queries ...
- 如何将html5程序打包成Android应用
问题分析: html5网站主要由html+css+js的形式组成,需要使用浏览器进行展现. Android需要使用Java语言来开发,对于前端工程师来说,无疑是增加了很大的难度. 随后出现了很多打包工 ...
- centos7通过yum安装MySQL
一:去官网查看最新安装包 https://dev.mysql.com/downloads/repo/yum/ 二:下载MySQL源安装包 wget http://dev.mysql.com/get/m ...
- spring boot 2.0.3+spring cloud (Finchley)8、微服务监控Spring Boot Admin
参考:Spring Boot Admin 2.0 上手 Spring Boot Admin 用于管理和监控一个或多个Spring Boot程序,在 Spring Boot Actuator 的基础上提 ...
- 1.ideal常用快捷键
Alt+回车 导入包,自动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码 Ctrl+Alt+O 优化导入的类和包Alt+Insert 生成代码(如ge ...
- excel表格添加固定宽高的图片
import xlsxwriter,xlrd import glob #打开excel文件 data=xlrd.open_workbook('优秀创意库-20180725.xlsx') #获取第一张工 ...
- MongoDB中的基础概念:Databases、Collections、Documents
MongoDB以BSON格式的文档(Documents)形式存储.Databases中包含集合(Collections),集合(Collections)中存储文档(Documents). BSON是一 ...
- php常用函数——字符串函数
php常用函数——字符串函数
- Linux下libevent安装与示例
http://www.cnblogs.com/kunhu/p/3632225.html
- MGR Switch single-Primary to Muti_primary
MGR single_primary 切换 Muti-Primary 模式 root@localhost [(none)]>select * from performance_schema.re ...