C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day, Hongcow goes to the store and sees a brand new deck of n special cards. Each individual card is eit…
Hongcow Buys a Deck of Cards 啊啊啊, 为什么我连这种垃圾dp都写不出来.. 不是应该10分钟就该秒掉的题吗.. 从dp想到暴力然后gg, 没有想到把省下的红色开成一维. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair&…
这题的难点在于状态的设计 首先显然是个状压,需要一维表示卡的状态,另一维如果设计成天数,难以知道当前的钱数,没法确定是否能够购买新的卡,如果设计成钱数,会发现状态数过多,空间与时间都无法承受.但是可以发现,如果没有买卡的钱会因当前卡数变化而变化这个条件的话,买卡的钱是一定的,而我们因拥有卡而省的钱不会超过120(1+2+3+...+15).所以可以将状态设计成f[i][j]表示卡的状态为i,省了j个红币,能省多少个蓝币. 然后就结束了... 注意所有下标为状态的数组的大小T T... #incl…
题意:现在有n张卡片(n <= 16), 每一轮你可以执行两种操作中的一种.1:获得一张红色令牌和一张蓝色令牌.2:购买一张卡片(如果可以买的话),购买的时候蓝色卡片可以充当蓝色令牌,红色同理,但是购买后只消耗令牌,不消耗卡片.问最少多少轮可以购买全部卡片. 思路1:状压DP.我们发现卡片可以减少令牌的使用,如果不考虑卡片的话,总花费其实是固定的.所以,只要我们算出了通过令牌最多可以减免多少花费,就可以得到答案了. 设dp[i][j]为卡片的够买状态为i时,其中红色卡片的花费减免了j,蓝色卡片花…
地址:http://codeforces.com/problemset/problem/744/C 题目: C. Hongcow Buys a Deck of Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day, Hongcow goes to the store and sees a brand ne…
大意: n个红黑卡, 每天可以选择领取一块红币一块黑币, 或者买一张卡, 第$i$张卡的花费红币数$max(r_i-A,0)$, 花费黑币数$max(b_i-B,0)$, A为当前红卡数, B为当前黑卡数, 求买完所有卡最少天数. 这题挺巧妙的, 刚开始看花费的范围太大一直在想怎么贪心... 实际上注意到减费最多只有120, 可以按照减费进行dp即可 这题CF大神的最优解写了个模拟退火ORZ #include <iostream> #include <algorithm> #inc…
题意 你有\(n\)个物品,物品和硬币有\(A\),\(B\)两种类型,假设你有\(M\)个\(A\)物品和\(N\)个\(B\)物品 每一轮你可以选择获得\(A, B\)硬币各\(1\)个,或者(硬币足够)花\(\max(a_i - M, 0)\)个\(A\),\(\max(b_i - N, 0)\)个\(B\)买\(i\)这个物品 问买到所有物品最少要多少轮 题解 巧妙的\(dp\),考虑间接设计状态 \(f[S][A] = B\)表示\(S\)这个集合买过了,\(A\)类花\(\sum a…
题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vlad is fond of popular computer game Bota-2. Recently, the developers…
F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course…
In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where: Each group has exactly X cards. All the cards in eac…