这个题有点意思,其实不是特别难,但是不太好想...中间用二分找最大的可买长度就行了. 题干: 题目描述 Farmer John <= K <= ), each with value ..,,. FJ would like to make a sequence of N purchases ( <= N <= ,), <= c(i) <= ,). As he makes this sequence of purchases, he can periodically sto…
传送门 先通过二分预处理出来,每个硬币在每个商品处最多能往后买多少个商品 直接状压DP即可 f[i]就为,所有比状态i少一个硬币j的状态所能达到的最远距离,在加上硬币j在当前位置所能达到的距离,所有的取max 是满足最优解性质的 #include <cstdio> #include <iostream> #include <algorithm> #define N 17 #define max(x, y) ((x) > (y) ? (x) : (y)) int n…
[BZOJ3312][Usaco2013 Nov]No Change Description Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 <= K <= 16), each with value in the range 1..100,000,000. FJ would like to make a sequence of N purchases…
[USACO13NOV]没有找零No Change 题目链接 https://www.luogu.org/problemnew/show/3092 做题背景 FJ不是一个合格的消费者,不知法懂法用法,不会拿起法律的武器维护消费者权益 做法 本题涉及的知识点:状态压缩,动态规划,二分答案. 注意物品是依次购买 首先是状态压缩: 压什么?我们注意到k<=16,那么就是压硬币使用集合. 然后是动态规划: 怎么设状态?设dp[i]表示我们选硬币集合i(状压)从一号物品开始最多能买的物品数. 怎么转移?从…
P3092 [USACO13NOV]没有找零No Change 题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 <= K <= 16), each with value in the range 1..100,000,000. FJ would like to make a sequence of N purchases (1 <= N…
状压\(DP\) + 二分 考虑构成:\(k<=16\)所以根据\(k\)构造状压\(dp\),将所有硬币的使用情况进行状态压缩 考虑状态:数组\(dp[i]\)表示用\(i\)状态下的硬币可以购买到第几个商品 ,\(f[i]\)表示状态\(i\)下的花费 考虑转移:使用当前硬币的状态一定由使用上一个硬币的状态转移而来 举个例子:之前状态\(x\):\(dp[x] = y\), \(i = 2 = (010)_2\) ,当前枚举到的状态\(i = 3 = (011)_2\) , \(dp[i]…
题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 <= K <= 16), each with value in the range 1..100,000,000. FJ would like to make a sequence of N purchases (1 <= N <= 100,000), where the ith p…
题目描述 Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins (1 <= K <= 16), each with value in the range 1..100,000,000. FJ would like to make a sequence of N purchases (1 <= N <= 100,000), where the ith p…
Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one day, the king of Rompire was captured by human beings. His thinking circuit was changed by human and thus became a tyrant. All those who are against him…
题目传送门 可能是我退役/NOIP前做的最后一道状压... 题目大意:给你\(k\)个硬币,FJ想按顺序买\(n\)个物品,但是不能找零,问你最后最多剩下多少钱. 注意到\(k<=16\),提示状压.开始设计的状态是\(f[i]\)表示在状态\(i\)下最多剩的钱数,后来发现不好搞因为可能有无解的情况.这种情况我们不妨把状态设计的再"退化"一点,也就是不那么贴近最终的结果,只是一个中间的部分.设\(f[i]\)为在状态\(i\)下,最多能购买的物品数. 因为是按顺序购买的,所以有…