CF744C Hongcow Buys a Deck of Cards
题目描述
一天,小红牛去商店看到了一副全新的 $n$ 特殊卡牌。每张卡片都是红色或蓝色的。他决定立刻购买它们。为了做到这一点,他需要和商店的老板玩一个游戏。
这个游戏需要一定数量的回合才能完成。在每个回合,小红牛可以做两件事中的一件:
- 收集代币。选择这个选项,小红牛可以收集 $1$ 个红色代币和 $1$ 个蓝色代币(因此,每次操作总共 $2$ 个代币)。
- 购买一张卡片。小红牛选择一张卡片,并花费代币按照以下规定购买它。
第 $i$ 张卡片需要 $r_i$ 个红色资源和 $b_i$ 个蓝色资源。假设小红牛当前有 $A$ 张红色卡片和 $B$ 张蓝色卡片。那么,第 $i$ 张卡片将需要小红牛花费 $\max(r_i - A, 0)$ 个红色代币和 $\max(b_i - B, 0)$ 个蓝色代币。注意,只有代币会消失,但卡片会永远留在小红牛手中。每张卡片只能购买一次。
根据卡片及其成本的描述,确定小红牛购买所有卡片所需的最少回合数。
输入格式
输入的第一行将包含一个整数 $n$($1 \le n \le 16$)。
接下来的 $n$ 行输入将包含三个标记 $c_i$、$r_i$ 和 $b_i$。$c_i$ 将是 `R` 或 `B`,表示卡片的颜色为红色或蓝色。$r_i$ 将是一个整数,表示获取该卡片所需的红色资源数量,$b_i$ 将是一个整数,表示获取该卡片所需的蓝色资源数量($0 \le r_i, b_i \le 10^7$)。
输出格式
输出一个整数,表示获取所有卡片所需的最少回合数。
说明/提示
For the first sample, Hongcow's four moves are as follows:
1. Collect tokens
2. Buy card $ 1 $
3. Buy card $ 2 $
4. 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:
1. Collect tokens
2. Collect tokens
3. Buy card $ 2 $
4. Collect tokens
5. Buy card $ 3 $
6. 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.