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. 淘淘商城之springmvc和mybatis整合

    一.需求 使用springmvc和mybatis完成商品列表查询 二.整合思路 springmvc+mybaits的系统架构: 第一步:整合dao层 mybatis和spring整合,通过spring ...

  2. luogu P2516 [HAOI2010]最长公共子序列

    传送门 首先那个\(O(n^2)\)的dp都会吧,不会自己找博客或者问别人,或是去做模板题(误) 对以下内容不理解的,强势推荐flash的博客 我们除了原来记录最长上升子序列的\(f_{i,j}\), ...

  3. MySQL中查询行数最多的表并且排序

    #切换到schema use information_schema; #查询数据量最大的30张表 并排序 select table_name,table_rows from tables order ...

  4. C# List分页

    假设你每页10条数据当前是第3页 跳到第4页则:List.Skip((4-1)*10).Take(10) 本文来自SunShine,转载请标明出处: http://do.jhost.cn/sunshi ...

  5. phantomjs 解码url

    以下为部分代码: var htmlnodeInfo=(allADUrlElements.snapshotItem(i).getAttribute("href").match(/\* ...

  6. oracle巡检脚本备份

    重做日志生成情况,一天生成日志大小:select round(sum(blocks*block_size)/1024/1024/1024,2) BLOCK from v\$archived_log w ...

  7. Qt Ubuntu 编译出错-1: error: 找不到 -lGL

    安装好,编译界面程序出错“-1: error: 找不到 -lGL” 在终端运行如下命令(安装Qt5.8.0) sudo apt-get install libqt5-dev sudo apt-get ...

  8. apache服务器的常用功能及设置

    安装httpd yum -y install  httpd     服务脚本:/etc/rc.d/init.d/httpd        脚本配置文件:/etc/sysconfig/httpd     ...

  9. jmeter之使用代理录制脚本

    从loadrunner到jmeter,录制压力测试脚本好像都只支持IE,近来才知道jmeter还有自带的录制脚本元件, 且支持IE.Chrome及Firefox等多种浏览器.这里就记录一下通过jmet ...

  10. nodejs后台向后台get请求

    1 前言 有时在nodejs写的服务端某方法需要向服务端另一个接口发送get请求,可以使用第三方库,然后直接使用即可,此文章只是用来记录使用 2 方法 2.1 get 请求 //1. Install ...