UVA 7392 Bundles of Joy(乱搞)
来源:互联网 发布:淘宝和阿里巴巴哪个好 编辑:程序博客网 时间:2024/05/17 21:41
给定蛋糕店的蛋糕,问花最少的钱买所有的n个蛋糕
#include<bits/stdc++.h>using namespace std;typedef long long ll;struct node{ll dp;ll now;vector<int>v;vector<int>tree;};bool com(const node &x, const node &y){return x.v.size() < y.v.size();}int fa[500];node a[2000];void init(){memset(fa, -1, sizeof fa);for (int i = 0; i < 200; i++){a[i].dp = -1;a[i].v.clear();a[i].tree.clear();}}int main(){int T;cin >> T;while (T--){int n, m;init();scanf("%d%d", &n, &m);for (int i = 1; i <= n; i++)a[0].v.push_back(i);a[0].now = 999999999999;int cnt = 0;for (int i = 1; i <= m; i++){int x;scanf("%lld%d", &a[i].now, &x);for (int j = 0; j < x; j++){int y;scanf("%d", &y);a[i].v.push_back(y);}}sort(a, a + m + 1, com);for (int i = 0; i <= m; i++){node &z = a[i];set<int>ss;ll ans = 0; int flag = 0;for (int j = 0; j < z.v.size(); j++){if (fa[z.v[j]] == -1)flag = 1;else ss.insert(fa[z.v[j]]);fa[z.v[j]] = i;}set<int>::iterator po;for (po = ss.begin(); po != ss.end(); po++){z.tree.push_back(*po);ans += a[*po].dp;}if (!flag)z.dp = min(z.now, ans);else z.dp = z.now;}cout << a[m].dp << endl;}}
0 0
- UVA 7392 Bundles of Joy(乱搞)
- Bundles of Joy
- Bundles of Joy
- UVALive 7392 Bundles of Joy【bitset】【类树形DP】【杂题】
- UVALive-7392 - Bundles of Joy【树型DP】【深搜】【好题】
- joy of data
- A Lot of Joy
- The Joy of Clojure 笔记
- Realms Of Joy - Time Of Light.
- joy
- Joy of SAX:Visual Basic 的示例
- The Joy of Living 生活的乐趣
- The Joy of Living-生活的乐趣
- Git's Little Bundle of Joy
- A Lot of Joy-Gym 100187B
- Gym 100187B - A Lot of Joy
- Box of Bundles:免费设计资源网站
- Hello, JIT World: The Joy of Simple JITs
- 【机器学习实战04】k-均值聚类算法
- 进程同步之信号量机制(pv操作)及三个经典同步问题
- 让你的程序性能获得百倍的提升—Redis基础使用指南
- jzoj 4718. 【GDOI2017模拟7.20】准备食物2 费用流
- javaweb中的filter
- UVA 7392 Bundles of Joy(乱搞)
- Redis和Memcache的区别
- Http--基础理解
- java中懒汉饿汉编写及比较
- 腾讯web前端2016面试
- 翻转子串的解题技巧
- #248 Count of Smaller Number
- 农历日期转换
- Zookeeper之——最简单的安装配置方式