CF816E-Karen and Supermarket】的更多相关文章

传送门 - > \(CF816E\) Karen and Supermarket 题意翻译 在回家的路上,凯伦决定到超市停下来买一些杂货. 她需要买很多东西,但因为她是学生,所以她的预算仍然很有限. 事实上,她只花了b美元. 超市出售N种商品.第i件商品可以以ci美元的价格购买.当然,每件商品只能买一次. 最近,超市一直在努力促销.凯伦作为一个忠实的客户,收到了n张优惠券. 如果凯伦购买i次商品,她可以用i次优惠券降低di美元. 当然,不买对应的商品,优惠券不能使用. 然而,对于优惠券有一个规则…
Karen and Supermarket 感觉就是很普通的树形dp. dp[ i ][ 0 ][ u ]表示在 i 这棵子树中选择 u 个且 i 不用优惠券的最小花费. dp[ i ][ 1 ][ u ]表示在 i 这棵子树中选择 u 个且 i 用优惠券的最小花费. 注意这个转移总的合起来是O(n ^ 2)的. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk…
题目链接 CF815C Karen and Supermarket 题解 只要在最大化数量的前提下,最小化花费就好了 这个数量枚举ok, dp[i][j][1/0]表示节点i的子树中买了j件商品 i 优惠了 / 没优惠 复杂度是n^2的 因为每次是新儿子节点的siz * 之前儿子几点的siz, 就相当于树上的节点两两匹配,这个匹配只会在lca处计算一次 代码 #include<cstdio> #include<cstring> #include<algorithm> #…
题目传送门 Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. T…
E. Karen and Supermarket time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, b…
C. Karen and Supermarket     On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars.…
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods…
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods…
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods…
Codeforces 815 C 考虑树型dp. \(dp[i][0/1][k]\)表示现在在第i个节点, 父亲节点有没有选用优惠, 这个子树中买k个节点所需要花的最小代价. 然后转移的时候枚举i的一个儿子u, 然后还要枚举在u的子树中选择了多少个节点l, 则\(dp[i][0/1][k+l]=dp[i][0/1][k]+dp[u][0/1][l]\). 还要注意转移顺序. 最后枚举最后一个\(dp[1][1][i]\leq limit\)的i就是答案.…