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 ...
随机推荐
- C语言 百炼成钢25
/* 题目61:编写一个名为removestring的函数,该函数用于从一个字符串中删除一定量的字符. 该函数接受三个参数: 第1参数代表源字符串 第2参数代表需要删除字符的起始位置(位置从0开始) ...
- c# 实现遍历 DataTable 和DataSet (简单的方式)
今天 做一个小程序 ,遇到了这样一个 问题就是 怎样简单的 遍历一个 DataTable 一. DataTable table= DBhelper.GetDataTable(str);foreach( ...
- 2017 ACM区域赛(西安) 参赛流水账
day 0: 周五, 鸽了概统课,早上和紫金港的几位小伙伴一起打车去萧山机场,从咸阳机场到西北工业大学坐了五十多个站的公交车,感觉身体被掏空.晚上在宾馆本来打算补之前训练的一个题,想想还是先花个十来分 ...
- DevExpress 控件使用技巧
DevExpress是非常主流的.NET控件,眼下全世界和中国都用非常多用户使用,只是因为是英文版,初次接触的同学可能会认为困难.这里就总结DevExpress常见的10个使用技巧. 1.TextEd ...
- DB2 SQL Error: SQLCODE=-668, SQLSTATE=57016错误解决方法
这个错误是:表处于"装入暂挂"状态. 经多次尝试 总结方法: 1:reorg table <表>: 假如不好使 则下面方法 2,先前尝试装入(LOAD)此表失败.表的状 ...
- html空格字符
一.使用全角空格IDEOGRAPHIC SPACE---- Encodings HTML Entity (decimal) HTML Entity (hex) How to type in ...
- word页眉与页脚详解
1.如何隔离封面等不需要插入页码的页面: 首先插入分节符下一页(一定是分节符),再在下一页(即要开始插入页码的页面)选择视图-->页眉和页脚-->设置为取消链接到前一页.设置页码格式为起始 ...
- iOS-.pch如何使用
今天我们要说的是.pch这个文件 我相信大家并不陌生,因为如果是新手开发工程师 总会被它搞得总报错误. 那么我们要知道.pch到底是干什么的,说白了就是一个预编译文件,在运行程序之前,要对头文件等一些 ...
- 10013: An attempt was made to access a socket in a way forbidden by its access permissions
nginx的error.log日志报错: 2018/01/25 11:55:22 [emerg] 3380#15488: bind() to 0.0.0.0:20003 failed (10013: ...
- maven2报xxxServlet cannot be cast to javax.servlet
由于CacheFilter实现了javax.servlet.Filter接口,Filter是在servlet-api.jar里,因此pom中有 <dependency> ...