CF815C Karen and Supermarket】的更多相关文章

题目链接 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…
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…
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.…
传送门 Luogu 解题思路 树形背包. 设 \(f[i][j][0/1]\) 表示在以 \(i\) 为根的子树中选 \(j\) 件商品的最少花费. 边界条件: \(f[i][j][0] = \min\limits_{0\le k\le siz[son]}\left\{f[i][j - k][0]+f[son][k][0]\right\}\) \(f[i][j][1] = \min\limits_{0\le k\le siz[son]}\left\{f[i][j - k][1]+f[son][k…
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就是答案.…