Hongcow Buys a Deck of Cards

啊啊啊, 为什么我连这种垃圾dp都写不出来。。 不是应该10分钟就该秒掉的题吗。。

从dp想到暴力然后gg, 没有想到把省下的红色开成一维。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n;
int c[N], r[N], b[N], R, B;
char s[]; int dp[ << N][];
int Sr[ << N], Sb[ << N]; int main() {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%s%d%d", s, &r[i], &b[i]);
if(s[] == 'R') c[i] = ;
else c[i] = ;
R += r[i];
B += b[i];
}
for(int S = ; S < ( << n); S++) {
for(int i = ; i < n; i++)
if(S >> i & ) Sr[S] += !c[i], Sb[S] += c[i];
}
int ans = inf;
memset(dp, -, sizeof(dp));
dp[][] = ;
for(int S = ; S < ( << n); S++) {
for(int i = ; i <= ; i++) {
if(dp[S][i] == -) continue;
for(int j = ; j < n; j++) {
if(S >> j & ) continue;
dp[S | ( << j)][i + min(r[j], Sr[S])] = max(dp[S | ( << j)][i + min(r[j], Sr[S])], dp[S][i] + min(b[j], Sb[S]));
}
}
if(S == ( << n) - ) {
for(int i = ; i <= ; i++) {
if(dp[S][i] == -) continue;
ans = min(ans, max(R - i, B - dp[S][i]) + n);
}
}
}
printf("%d\n", ans);
return ;
} /*
*/

Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)的更多相关文章

  1. Codeforces 745E Hongcow Buys a Deck of Cards 状压DP / 模拟退火

    题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理, ...

  2. codeforces 744C Hongcow Buys a Deck of Cards

    C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes in ...

  3. Codeforces 744C. Hongcow Buys a Deck of Cards(状压DP)

    这题的难点在于状态的设计 首先显然是个状压,需要一维表示卡的状态,另一维如果设计成天数,难以知道当前的钱数,没法确定是否能够购买新的卡,如果设计成钱数,会发现状态数过多,空间与时间都无法承受.但是可以 ...

  4. Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards

    地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per ...

  5. Codeforces Beta Round #8 C. Looking for Order 状压dp

    题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 second ...

  6. Codeforces 453B Little Pony and Harmony Chest:状压dp【记录转移路径】

    题目链接:http://codeforces.com/problemset/problem/453/B 题意: 给你一个长度为n的数列a,让你构造一个长度为n的数列b. 在保证b中任意两数gcd都为1 ...

  7. Codeforces 1383C - String Transformation 2(找性质+状压 dp)

    Codeforces 题面传送门 & 洛谷题面传送门 神奇的强迫症效应,一场只要 AC 了 A.B.D.E.F,就一定会把 C 补掉( 感觉这个 C 难度比 D 难度高啊-- 首先考虑对问题进 ...

  8. Hongcow Buys a Deck of Cards CodeForces - 744C (状压)

    大意: n个红黑卡, 每天可以选择领取一块红币一块黑币, 或者买一张卡, 第$i$张卡的花费红币数$max(r_i-A,0)$, 花费黑币数$max(b_i-B,0)$, A为当前红卡数, B为当前黑 ...

  9. 「CF744C」Hongcow Buys a Deck of Cards「状压 DP」

    题意 你有\(n\)个物品,物品和硬币有\(A\),\(B\)两种类型,假设你有\(M\)个\(A\)物品和\(N\)个\(B\)物品 每一轮你可以选择获得\(A, B\)硬币各\(1\)个,或者(硬 ...

随机推荐

  1. HTML5的manifest 本地离线缓存

    下面直接放测试代码: index.html <!DOCTYPE html> <html manifest="m.manifest"> <head> ...

  2. Javaweb学习笔记——(四)——————JavaScript基础&DOM目录

    1.案例一:在末尾添加节点 第一个:获取到ul标签 第二部:创建li标签 document.createElement("标签名称")方法 第三步:创建文本 document.cr ...

  3. OO第三阶段总结

    软件形式化方法历史 形式化方法的研究高潮始于20世纪60年代后期,针对当时所谓"软件危机",人们提出种种解决方法,归纳起来有两类:一是采用工程方法来组织.管理软件的开发过程:二是深 ...

  4. 关于apache 开启 ssl https 支持 TLS1.2 的些事

    项目背景 需要搭建一个小程序的服务器,当然要使用https协议服务器windows service 2012 r2,后台语言是php,服务集成环境装的是appserv2.5 ,apache2.2证书申 ...

  5. FPN-Feature Pyramid Networks for Object Detection

    FPN-Feature Pyramid Networks for Object Detection 标签(空格分隔): 深度学习 目标检测 这次学习的论文是FPN,是关于解决多尺度问题的一篇论文.记录 ...

  6. Builder建造者模式

  7. 线路板(PCB)制作流程中英文对照表

    线路板(PCB)流程术语中英文对照流程简介:开料--钻孔--干膜制程--压合--减铜--电镀--塞孔--防焊(绿漆/绿油) --镀金--喷锡--成型--开短路测试--终检--雷射钻孔A. 开料( Cu ...

  8. SpringBoot使用thymeleaf模板引擎

    (1).添加pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  9. Python startswith() 函数 判断字符串开头

    Python startswith() 函数 判断字符串开头 函数:startswith() 作用:判断字符串是否以指定字符或子字符串开头 一.函数说明语法:string.startswith(str ...

  10. #ifndef详解

    #ifndef 是"if not defined"的简写,是预处理功能(宏定义.文件包含.条件编译)当中的条件编译,可以根据是否已经定义了一个变量来进行分支选择,其作用是: 1.防 ...