Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards
地址:http://codeforces.com/problemset/problem/744/C
题目:
2 seconds
256 megabytes
standard input
standard output
One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.
This game takes some number of turns to complete. On a turn, Hongcow may do one of two things:
- Collect tokens. Hongcow collects 1 red token and 1 blue token by choosing this option (thus, 2 tokens in total per one operation).
- Buy a card. Hongcow chooses some card and spends tokens to purchase it as specified below.
The i-th card requires ri red resources and bi blue resources. Suppose Hongcow currently has A red cards and B blue cards. Then, the i-th card will require Hongcow to spend max(ri - A, 0) red tokens, and max(bi - B, 0) blue tokens. Note, only tokens disappear, but the cards stay with Hongcow forever. Each card can be bought only once.
Given a description of the cards and their costs determine the minimum number of turns Hongcow needs to purchase all cards.
The first line of input will contain a single integer n (1 ≤ n ≤ 16).
The next n lines of input will contain three tokens ci, ri and bi. ci will be 'R' or 'B', denoting the color of the card as red or blue. ri will be an integer denoting the amount of red resources required to obtain the card, and bi will be an integer denoting the amount of blue resources required to obtain the card (0 ≤ ri, bi ≤ 107).
Output a single integer, denoting the minimum number of turns needed to acquire all the cards.
3
R 0 1
B 1 0
R 1 1
4
3
R 3 0
R 2 0
R 1 0
6
For the first sample, Hongcow's four moves are as follows:
- Collect tokens
- Buy card 1
- Buy card 2
- Buy card 3
Note, at the fourth step, Hongcow is able to buy card 3 because Hongcow already has one red and one blue card, so we don't need to collect tokens.
For the second sample, one optimal strategy is as follows:
- Collect tokens
- Collect tokens
- Buy card 2
- Collect tokens
- Buy card 3
- Buy card 1
At the fifth step, even though Hongcow has a red token, Hongcow doesn't actually need to spend it, since Hongcow has a red card already.
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,sz,sumr,sumb,r[],b[],dp[<<][],srr[],sbb[];
char col[];
int main(void)
{
cin>>n;
sz=<<n;
for(int i=;i<n;i++)
scanf("%s%d%d",col+i,r+i,b+i),sumr+=r[i],sumb+=b[i];
memset(dp,0xef,sizeof(dp));
dp[][]=;
for(int i=;i<sz;i++)
{
int sr,sb;
sr=sb=;
for(int j=;j<n;j++)
if(i&(<<j))
col[j]=='R'?sr++:sb++;
for(int j=;j<n;j++)
if(!(i&(<<j)))
srr[j]=min(sr,r[j]),sbb[j]=min(sb,b[j]);
for(int j=;j<n;j++)
if(!(i&(<<j)))
for(int k=;k<=;k++)
dp[i|(<<j)][k+srr[j]]=max(dp[i|(<<j)][k+srr[j]],dp[i][k]+sbb[j]);
}
int ans=2e9;
for(int i=;i<=;i++)
ans=min(max(sumr-i,sumb-dp[sz-][i]),ans);
printf("%d\n",ans+n);
return ;
}
Codeforces Round #385 (Div. 1) C. Hongcow Buys a Deck of Cards的更多相关文章
- Codeforces Round #385 (Div. 2) B - Hongcow Solves A Puzzle 暴力
B - Hongcow Solves A Puzzle 题目连接: http://codeforces.com/contest/745/problem/B Description Hongcow li ...
- Codeforces Round #385 (Div. 2) A. Hongcow Learns the Cyclic Shift 水题
A. Hongcow Learns the Cyclic Shift 题目连接: http://codeforces.com/contest/745/problem/A Description Hon ...
- Codeforces Round #385 (Div. 2) C - Hongcow Builds A Nation
题目链接:http://codeforces.com/contest/745/problem/C 题意:给出n个点m条边,还有k个不能连通的点,问最多能添加几条边. 要知道如果有n个点最多的边是n*( ...
- 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 ...
- Codeforces 744C Hongcow Buys a Deck of Cards 状压dp (看题解)
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. ...
- Codeforces Round #385 (Div. 2) Hongcow Builds A Nation —— 图论计数
题目链接:http://codeforces.com/contest/745/problem/C C. Hongcow Builds A Nation time limit per test 2 se ...
- Codeforces Round #385(div 2)
A =w= B QwQ C 题意:n个点m条边的无向图,其中有k个特殊点,你在这张图上尽可能多的连边,要求k个特殊点两两不连通,问最多能连多少边 分析:并查集 对原图做一次并查集,找出特殊点所在集合中 ...
- Codeforces Round #385 (Div. 2) A,B,C 暴力,模拟,并查集
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces Round #385 (Div. 2)A B C 模拟 水 并查集
A. Hongcow Learns the Cyclic Shift time limit per test 2 seconds memory limit per test 256 megabytes ...
随机推荐
- Python之Matplotlib库常用函数大全(含注释)
plt.savefig(‘test’, dpi = 600) :将绘制的图画保存成png格式,命名为 test plt.ylabel(‘Grade’) : y轴的名称 plt.axis([-1, 1 ...
- 1小时轻松上手springmvc,视频网站后台开发
由于最近半年一直在用springboot,但是也不能忘了本,于是把springmvc重新练了下,做了个前端传个表单,后台接收并显示的界面,该项目可以上传视频的URL,然后前端进行页面的播放,项目采用s ...
- SmartUI2.0后续声明
感谢很多朋友关注,因为今年一直在另外一个公司做顾问,网络环境管制相当严格,所以一直没有更新博客. 同时也很抱歉,SmartUI 2.0一直都没有下文.在次声明一下,SmartUI一直都在做,只不过Sm ...
- openwrt U盘启动
参考链接: http://m.blog.csdn.net/blog/zcynical/44892785
- iOS开源库–最全的整理
本文转载至 http://www.code4blog.com/archives/505 youtube下载神器:https://github.com/rg3/youtube-dl我擦咧vim插件:ht ...
- 《ASP.NET 1200例》ref关键字与out关键字
REF关键字 ref 关键字会导致通过引用传递的参数,而不是值. 通过引用传递的效果是在方法中对参数的任何改变都会反映在调用方的基础参数中. 引用参数的值与基础参数变量的值始终是一样的. 不要将“通过 ...
- JS制作一个通用的商城版历史浏览记录
正在开发一个b2c的国外商城,昨天做了一个历史浏览记录发出来跟大家分享一下. JS: //cookie相关函数 function getCookieVal(offset) { var endst ...
- mysql查询某天是本年第几周
SELECT WEEK(date_add('2012-12-31',interval 6 day),2);
- 《挑战程序设计竞赛》2.3 动态规划-进阶 POJ1065 1631 3666 2392 2184(5)
POJ1065: Description There is a pile of n wooden sticks. The length and weight of each stick are kno ...
- 如何查看python的api
如何查看python selenium的api 经常发现很多同学装好了python+selenium webdriver开发环境后不知道怎么去查看api文档,在这里乙醇简单介绍一下具体方法,其实非 ...