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

这题挺巧妙的, 刚开始看花费的范围太大一直在想怎么贪心...

实际上注意到减费最多只有120, 可以按照减费进行dp即可

这题CF大神的最优解写了个模拟退火ORZ

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head const int N = 20;
int n;
char c[N];
int x[N], y[N];
int dp[1<<16][150];
void chkmax(int &a, int b) {a=max(a,b);}
int main() {
scanf("%d", &n);
REP(i,0,n-1) scanf(" %c%d%d", c+i, x+i, y+i);
memset(dp, 0xbc, sizeof dp);
dp[0][0] = 0;
int mx = (1<<n)-1;
REP(i,0,mx-1) {
int A = 0, B = 0;
REP(k,0,n-1) if (i>>k&1) {
if (c[k]=='R') ++A;
else ++B;
}
REP(k,0,n-1) if (!(i>>k&1)) {
REP(j,0,120) if (dp[i][j]!=0xbcbcbcbc) {
chkmax(dp[i^1<<k][j+min(x[k], A)],dp[i][j]+min(y[k], B));
}
}
}
int ans = INF, X = 0, Y = 0;
REP(i,0,n-1) X+=x[i], Y+=y[i];
REP(i,0,120) ans = min(ans, max(X-i, Y-dp[mx][i]));
printf("%d\n", ans+n);
}

Hongcow Buys a Deck of Cards CodeForces - 744C (状压)的更多相关文章

  1. 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 ...

  2. Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)

    Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...

  3. 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 ...

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

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

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

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

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

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

  7. Vladik and cards CodeForces - 743E (状压)

    大意: 给定序列, 求选出一个最长的子序列, 使得任选两个[1,8]的数字, 在子序列中的出现次数差不超过1, 且子序列中相同数字连续. 正解是状压dp, 先二分转为判断[1,8]出现次数>=x ...

  8. codeforces 1185G1 状压dp

    codeforces 1185G1. Playlist for Polycarp (easy version)(动态规划) 传送门:https://codeforces.com/contest/118 ...

  9. CodeForces 11D(状压DP 求图中环的个数)

    Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no re ...

随机推荐

  1. loj#2305. 「NOI2017」游戏 2-sat

    链接 https://loj.ac/problem/2305 https://www.luogu.org/problemnew/show/P3825 思路 3-sat神马的就不要想了,NP问题 除去x ...

  2. [bzoj 4034][HAOI 2015]树上操作

    Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中 ...

  3. (转载)http和socket之长连接和短连接区别

    TCP/IPTCP/IP是个协议组,可分为三个层次:网络层.传输层和应用层.在网络层有IP协议.ICMP协议.ARP协议.RARP协议和BOOTP协议.在传输层中有TCP协议与UDP协议.在应用层有: ...

  4. Java基础 【Math、Random、System、BigInteger、BigDecimal、Date、Calendar等常用类的使用】

    学习的这几个类  是日常工作中经常要使用到的类 Math 类包含用于执行基本数序运算的方法,如初等指数.对数.平方根和 三角函数. 成员方法 1.public static int abs(int a ...

  5. 在Mac OSX下安装Microsoft Calibri字体

    参考: Where can I find default Microsoft fonts Calibri, Cambria? 在Mac OSX下安装Microsoft Calibri字体 1.下载: ...

  6. numa.h:No such file or directory 解决方法

    参考: numa.h:No such file or directory numa.h:No such file or directory 解决方法 Ubuntu: $ apt-get install ...

  7. 《机器学习实战》之k-近邻算法(改进约会网站的配对效果)

    示例背景: 我的朋友海伦一直使用在线约会网站寻找合适自己的约会对象.尽管约会网站会推荐不同的人选,但她并不是喜欢每一个人.经过一番总结,她发现曾交往过三种类型的人: (1)不喜欢的人: (2)魅力一般 ...

  8. JavaScript(ES5)知识点梳理

    数据类型(null undefined number string boolean object)数据类型之间的相互转化(Boolean Number String parseInt parseFlo ...

  9. 【Python】【异步IO】

    # [[异步IO]] # [协程] '''协程,又称微线程,纤程.英文名Coroutine. 协程的概念很早就提出来了,但直到最近几年才在某些语言(如Lua)中得到广泛应用. 子程序,或者称为函数,在 ...

  10. Windows android appium python3 环境搭建

    安装nodejs https://www.cnblogs.com/sea-stream/p/10520624.html java 环境变量配置: https://www.cnblogs.com/sea ...