codeforces 417D. Cunning Gena 状压dp
2016-02-23 09:26
351 查看
题目链接
D. Cunning Gena
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.
The participants are offered m problems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing: the i-th friend asks Gena xi rubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at least ki monitors, each monitor costs b rubles.
Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there's no monitors connected to Gena's computer.
Input
The first line contains three integers n, m and b (1 ≤ n ≤ 100; 1 ≤ m ≤ 20; 1 ≤ b ≤ 109) — the number of Gena's friends, the number of problems and the cost of a single monitor.
The following 2n lines describe the friends. Lines number 2i and (2i + 1) contain the information about the i-th friend. The 2i-th line contains three integers xi, ki and mi (1 ≤ xi ≤ 109; 1 ≤ ki ≤ 109; 1 ≤ mi ≤ m) — the desired amount of money, monitors and the number of problems the friend can solve. The (2i + 1)-th line contains mi distinct positive integers — the numbers of problems that the i-th friend can solve. The problems are numbered from 1 to m.
Output
Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.
Sample test(s)
input
output
input
output
input
output
D. Cunning Gena
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him.
The participants are offered m problems on the contest. For each friend, Gena knows what problems he can solve. But Gena's friends won't agree to help Gena for nothing: the i-th friend asks Gena xi rubles for his help in solving all the problems he can. Also, the friend agreed to write a code for Gena only if Gena's computer is connected to at least ki monitors, each monitor costs b rubles.
Gena is careful with money, so he wants to spend as little money as possible to solve all the problems. Help Gena, tell him how to spend the smallest possible amount of money. Initially, there's no monitors connected to Gena's computer.
Input
The first line contains three integers n, m and b (1 ≤ n ≤ 100; 1 ≤ m ≤ 20; 1 ≤ b ≤ 109) — the number of Gena's friends, the number of problems and the cost of a single monitor.
The following 2n lines describe the friends. Lines number 2i and (2i + 1) contain the information about the i-th friend. The 2i-th line contains three integers xi, ki and mi (1 ≤ xi ≤ 109; 1 ≤ ki ≤ 109; 1 ≤ mi ≤ m) — the desired amount of money, monitors and the number of problems the friend can solve. The (2i + 1)-th line contains mi distinct positive integers — the numbers of problems that the i-th friend can solve. The problems are numbered from 1 to m.
Output
Print the minimum amount of money Gena needs to spend to solve all the problems. Or print -1, if this cannot be achieved.
Sample test(s)
input
2 2 1 100 1 1 2 100 2 1 1
output
202
input
3 2 5 100 1 1 1 100 1 1 2 200 1 2 1 2
output
205
input
1 2 1 1 1 1 1
output
-1 直接状态压缩就可以, 具体看代码。 inf要超级大才可以过。
#include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <queue> #include <stack> #include <bitset> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define mem(a) memset(a, 0, sizeof(a)) #define rson m+1, r, rt<<1|1 #define mem1(a) memset(a, -1, sizeof(a)) #define mem2(a) memset(a, 0x3f, sizeof(a)) #define rep(i, n, a) for(int i = a; i<n; i++) #define fi first #define se second typedef pair<int, int> pll; const double PI = acos(-1.0); const double eps = 1e-8; const int mod = 1e18+7; const ll inf = 5e18+7; const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} }; struct node { int x, k, c; bool operator < (node a) const { return k<a.k; } }a[105]; ll dp[(1<<23)]; int main() { int n, m, b, t, x; cin>>n>>m>>b; int ed = (1<<m)-1; for(int i = 1; i<=n; i++) { cin>>a[i].x>>a[i].k>>t; while(t--) { scanf("%d", &x); a[i].c |= 1<<(x-1); } } sort(a+1, a+1+n); for(int i = 1; i<=ed; i++) { dp[i] = inf; } ll ans = inf; for(int i = 1; i<=n; i++) { for(int j = 0; j<=ed; j++) { dp[j|a[i].c] = min(dp[j|a[i].c], dp[j]+a[i].x); } ans = min(ans, 1LL*a[i].k*b+dp[ed]); } if(ans == inf) { puts("-1"); } else { cout<<ans<<endl; } return 0; }
相关文章推荐
- easyui-prompt弹出框操作
- adb client, adb server, adbd原理浅析
- 在没有盗版的世界:Linux 桌面装机量占比可达40%
- C实例--推断一个字符串是否是回文数
- zoj 1003 Crashing Balloon
- 云舒网络:容器系列二:容器的视角-设计交付和架构
- Python中调用父类的同名方法
- VOC-release4.01 DPM训练的model(mat)转为OpenCV latentsvm可以加载的model(xml)
- ajax级联菜单实例代码下载
- JDK1.8的一些改动
- 在Eclipse中打开文件夹
- 使用xcode storyboard设置按钮圆角方法
- EMC FAST Cache和FAST VP简单比较
- 桥接 NAT HOST-ONLY
- jQuery拖拽排序插件制作拖拽排序效果(附源码下载)
- iOS simulator Code = 4
- redis
- C++语言-01-简介
- 花生壳免费域名80端口无法访问问题处理
- java UncaughtExceptionHandler 处理线程意外中止