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

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

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

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

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <math.h>
  5. #include <set>
  6. #include <map>
  7. #include <queue>
  8. #include <string>
  9. #include <string.h>
  10. #include <bitset>
  11. #define REP(i,a,n) for(int i=a;i<=n;++i)
  12. #define PER(i,a,n) for(int i=n;i>=a;--i)
  13. #define hr putchar(10)
  14. #define pb push_back
  15. #define lc (o<<1)
  16. #define rc (lc|1)
  17. #define mid ((l+r)>>1)
  18. #define ls lc,l,mid
  19. #define rs rc,mid+1,r
  20. #define x first
  21. #define y second
  22. #define io std::ios::sync_with_stdio(false)
  23. #define endl '\n'
  24. using namespace std;
  25. typedef long long ll;
  26. typedef pair<int,int> pii;
  27. const int P = 1e9+7, INF = 0x3f3f3f3f;
  28. ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
  29. 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;}
  30. ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
  31. //head
  32.  
  33. const int N = 20;
  34. int n;
  35. char c[N];
  36. int x[N], y[N];
  37. int dp[1<<16][150];
  38. void chkmax(int &a, int b) {a=max(a,b);}
  39. int main() {
  40. scanf("%d", &n);
  41. REP(i,0,n-1) scanf(" %c%d%d", c+i, x+i, y+i);
  42. memset(dp, 0xbc, sizeof dp);
  43. dp[0][0] = 0;
  44. int mx = (1<<n)-1;
  45. REP(i,0,mx-1) {
  46. int A = 0, B = 0;
  47. REP(k,0,n-1) if (i>>k&1) {
  48. if (c[k]=='R') ++A;
  49. else ++B;
  50. }
  51. REP(k,0,n-1) if (!(i>>k&1)) {
  52. REP(j,0,120) if (dp[i][j]!=0xbcbcbcbc) {
  53. chkmax(dp[i^1<<k][j+min(x[k], A)],dp[i][j]+min(y[k], B));
  54. }
  55. }
  56. }
  57. int ans = INF, X = 0, Y = 0;
  58. REP(i,0,n-1) X+=x[i], Y+=y[i];
  59. REP(i,0,120) ans = min(ans, max(X-i, Y-dp[mx][i]));
  60. printf("%d\n", ans+n);
  61. }

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. (转)ResNet, AlexNet, VGG, Inception: Understanding various architectures of Convolutional Networks

    ResNet, AlexNet, VGG, Inception: Understanding various architectures of Convolutional Networks by KO ...

  2. Python 网页解析器

    Python 有几种网页解析器? 1. 正则表达式 2.html.parser (Python自动) 3.BeautifulSoup(第三方)(功能比较强大) 是一个HTML/XML的解析器 4.lx ...

  3. 每日质量NPM包复制_copy-to-clipboard

    一.copy-to-clipboard 官方定义: Simple module exposing copy function 理解: 一个超级简单的复制功能,并且这种方法适用于通过别的事件触发复制功能 ...

  4. ros topic 发布一次可能会接收不到数据

    rostopic pub - /hdw_update hdw_driver/update_file_msg A B C D 系统提示: publishing and latching message ...

  5. Eclipse启动Web项目 Tomcat中webapps中没有项目文件夹

    原文出处:https://blog.csdn.net/JYH1314/article/details/51656233 1.eclipse不像MyEclipse默认将项目部署到tomcat安装目录下的 ...

  6. Discrete Log Algorithms :Baby-step giant-step

    离散对数的求解 1.暴力 2.Baby-step giant-step 3.Pollard’s ρ algorithm …… 下面搬运一下Baby-step giant-step 的做法 这是在 ht ...

  7. Spring分布式事务实现概览

    分布式事务,一直是实现分布式系统过程中最大的挑战.在只有单个数据源的单服务系统当中,只要这个数据源支持事务,例如大部分关系型数据库,和一些MQ服务,如activeMQ等,我们就可以很容易的实现事务. ...

  8. ButterKnife RadioGroup选择事件

    ButterKnife 的点击事件都很清晰,在使用RadioGroup控件时的方法: <!-- 定义一组单选框 --> <RadioGroup android:id="@+ ...

  9. Python中什么是变量

    在Python中,变量的概念基本上和初中代数的方程变量是一致的. 例如,对于方程式 y=x*x ,x就是变量.当x=2时,计算结果是4,当x=5时,计算结果是25. 只是在计算机程序中,变量不仅可以是 ...

  10. Fiddler 简单介绍

    fiddler 也已经使用了几年了,前面做免登录时就是用了fiddler,为了抓取cookie等信息.但是一直没有对他进行整理出一篇文章来介绍其使用. Fiddler的基本介绍 Fiddler的官方网 ...