Codeforces Round #222 (Div. 1) 博弈 + dp
2024-09-24 01:14:16
一般这种要倒着来。
#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 ;
} /*
*/
最新文章
- Deployment options
- Atitit java方法引用(Method References)&#160;与c#委托与脚本语言js的函数指针
- zabbix使用tokudb引擎替换innodb引擎
- URAL 1002 Phone Numbers(KMP+最短路orDP)
- VS2012创建MVC3项目提示错误: 此模板尝试加载组件程序集 “NuGet.VisualStudio.Interop, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”。
- 适配iOS9遇到的一些问题_Scheme白名单_ Bitcode及解决办法
- 再次深入理解delphi的类
- 【Python开发实战】Python环境的配置
- UI基础 - UIScrollView
- Hibernate整合Struts2时报错
- 【转】Directx11 HelloWorld之HLSL的Effect框架的使用
- 用邻接表或vector实现存边以及具体如何调用[模板]
- 201521123072《java程序设计》第五周学习总结
- pipelineDB初体验
- [译]Ocelot - Claims Transformation
- 附录A application.properties配置项
- eclipse设置
- EasyUI 在Tab页用button打开新Tab
- MySQL 安装与使用(二)
- HttpWebRequest抓取网页内容与直接输入URL得到的内容不一致!球大神帮忙!!
热门文章
- Rabbitmq--topic
- 「Django」rest_framework学习系列-序列化
- notepad++ 正则学习记录
- 前端PHP入门-033-连接数据库-天龙八步
- [DeeplearningAI笔记]序列模型1.1-1.2序列模型及其数学符号定义
- CF839 B 贪心
- 重构改善既有代码设计--重构手法13:Inline Class (将类内联化)
- css单位em、px、rem和pt的区别
- 【BZOJ】2049: [Sdoi2008]Cave 洞穴勘测 LCT
- 【VIJOS】P1512 SuperBrother打鼹鼠