一般这种要倒着来。

#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的更多相关文章

  1. Codeforces Round #222 (Div. 1) C. Captains Mode 对弈+dp

    题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ba ...

  2. 严格递增类的dp Codeforces Round #371 (Div. 1) C dp

    http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...

  3. 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp

    http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...

  4. Codeforces Round #548 (Div. 2) C dp or 排列组合

    https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...

  5. Codeforces Round #536 (Div. 2) E dp + set

    https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...

  6. Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)

    https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...

  7. Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希

    https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...

  8. Codeforces Round #222 (Div. 1) C. Captains Mode 状压

    C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...

  9. Codeforces Round #303 (Div. 2) C dp 贪心

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. varchar字段

    varchar  最长26000多,实际使用最好不要超过255,会占内存 可以考虑text

  2. width: calc(100% - 20px);

    width: calc(100% - 20px); css3 的 calc()函数.这里的意思是设置宽度比100%的宽度少20px. calc()函数用于动态计算长度值. calc()函数支持 &qu ...

  3. NDK编译时两 .so之间调用问题

    Android C++(NDK)项目需要调用别人的代码,因此将其编译成了.so库,而自己的代码也编成了一个.so库. 结果编译成功,但是在运行时自己的.so调用别人的.so会失败,提示说没有正确传入参 ...

  4. 在Eclipse中开发使用Spring IOC的JUnit/TestNG测试用例之详解

    转载自:http://blog.csdn.net/radic_feng/article/details/6740438 我们期望能像在产品代码中一样,在测试用例中使用的bean也由Spring Con ...

  5. centos7 nginx开启启动

    centos 7以上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度.关 ...

  6. JS零碎小知识

    filter()方法对数组进行过滤,生成新数组 var aqiNewData = aqiData.filter(function(data){ return data[1]>60; }); // ...

  7. Oracl闪回数据命令。

    当数据库操作没有备份,并且误删数据.可闪回任何 当前闪回15分钟前数据库状态.  alter table BASE_APPOINT_LOG enable row movement;flashback  ...

  8. CF745 C 并查集

    并查集由于政府不能连通我们可以先按给出的边建立连通块,再将不含有政府的点全部作为一个连通块,边数为(n-1)*n/2然后 贪心地将该连通块与[含政府的.且包含点数最多的]连通块相连,然后由于新增了一些 ...

  9. VS调试程序快捷键和系统快捷键

    调试程序快捷键 编译程序:F7 运行程序:ctrl + F5 打断点:F9 运行到断点位置:F5 单步执行:F10 单步进入函数:F11 结束调试:shift+F5 注释代码:ctrl+k,ctrl+ ...

  10. 【BZOJ3745】Norma [分治]

    Norma Time Limit: 20 Sec  Memory Limit: 64 MB[Submit][Status][Discuss] Description Input 第1行,一个整数N: ...