codeforces 815C Karen and Supermarket】的更多相关文章

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…
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…
LINK 思路 首先发现依赖关系是一个树形的结构 然后因为直接算花多少钱来统计贡献不是很好 因为数组开不下 那就可以算一个子树里面选多少个的最小代价就可以了 注意统计贡献的时候用优惠券的答案只能在1号点进行统计 //Author: dream_maker #include<bits/stdc++.h> using namespace std; //---------------------------------------------- //typename typedef long lon…
题意:有n件商品,每件商品都最多只能被买一次,且有一个原价和一个如果使用优惠券以后可以减少的价格,同时,除了第一件商品以外每件商品都有一个xi属性,表示买这个商品时如果要使用优惠券必须已经使用了xi的优惠券.现在有B的钱,问在不超过B的钱的情况下最多能买多少件商品. 做法:因为根据x属性,所有商品能够被连缀成一棵以1为根节点的树,因此考虑树形dp,因为n=5000,所以定义状态如下:dp[i][j][p],表示从i这件开始买,已经买了j件商品且i这件商品是否已经使用了优惠券(1表示使用,0表示没…
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.…
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac…
题目链接 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…
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就是答案.…