【codeforces 417D】Cunning Gena
【题目链接】:http://codeforces.com/problemset/problem/417/D
【题意】
有n个人共同完成m个任务;
每个人有可以完成的任务集(不一定所有任务都能完成);
(有重叠也无所谓);
然后它完成这些任务需要报酬xi;
同时它需要特殊物品的数量达到ki才会愿意去做这些任务;
这样特殊物品的单价为b;
然后问你完成这m个任务需要花费多少钱.
【题解】
假设我们最后选了几个人;
它们能够完成m项任务;
则这个特殊物品的数量应该是这些人里面ki的最大值;
根据这个;
我们一开始先把所有人的信息按照ki升序排;
然后做状态压缩DP;
设dp[i]表示完成任务的情况为i(用二进制表示)的最小花费;
则按照顺序选择;
如果在某一时刻;
dp[2m−1]有值了(或者发生了改变);
则可以直接用它+a[i].k*b来更新答案;
因为此时肯定是因为选择了第i个人,所以才发生了变化;
而又因为是升序排的,所以肯定是这个人的k值最大;
所以特殊物品的数量就是选择它啦.>_<
最后的答案大于1018QAQ
【Number Of WA】
1
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("D:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int M = 110e4;
const int N = 1e2+10;
struct abc{
int x,k,sta;
};
int temp,n,m;
LL dp[M],b,ans = -1;
abc a[N];
int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m >> b;
rep1(i,1,n){
int num;
cin >> a[i].x >> a[i].k >> num;
rep1(j,1,num){
int x;
cin >> x;
a[i].sta |= (1<<(x-1));
}
}
sort(a+1,a+1+n,[&](abc a,abc b){ return a.k<b.k;});
int ma = 1<<m;
ms(dp,-1);
dp[0] = 0;
rep1(i,1,n){
rep1(j,0,ma-1){
if (dp[j]==-1) continue;
int status = j | a[i].sta;
if (dp[status]==-1){
dp[status] = dp[j]+a[i].x;
}
else
dp[status] = min(dp[status],dp[j]+a[i].x);
}
if (dp[ma-1]!=-1){
if (ans==-1){
ans = dp[ma-1]+b*a[i].k;
}
else
ans = min(ans,dp[ma-1]+b*a[i].k);
}
}
if (ans==-1)
cout <<-1<<endl;
else
cout << ans << endl;
return 0;
}
【codeforces 417D】Cunning Gena的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- vscode快捷键补充
ctrl+enter 快速还到下行并插入一行 ctrl+shift+enter 快速换到上行并插入一行 ctrl+~ ctrl+1 快速在终端与代码区切换 ctrl+i 选中一行 ctrl + p: ...
- BZOJ 3126 [USACO2013 Open]Photo (单调队列优化DP)
洛谷传送门 题目大意:给你一个长度为$n$的序列和$m$个区间,每个区间内有且仅有一个1,其它数必须是0,求整个序列中数字1最多的数量 神题,竟然是$DP$ 定义$f_{i}$表示第i位放一个1时,最 ...
- 使用tf.ConfigProto()配置Session运行参数和GPU设备指定
参考链接:https://blog.csdn.net/dcrmg/article/details/79091941 tf.ConfigProto()函数用在创建session的时候,用来对sessio ...
- pytorch 4 regression 回归
import torch import torch.nn.functional as F import matplotlib.pyplot as plt # torch.manual_seed(1) ...
- ASP.NET-AuthorizeAttribute做身份验证操作
代码顺序为:OnAuthorization-->AuthorizeCore-->HandleUnauthorizedRequest 如果AuthorizeCore返回false时,才会走H ...
- COGS——T 438. 烦人的幻灯片
http://www.cogs.pro/cogs/problem/problem.php?pid=438 ★☆ 输入文件:slides.in 输出文件:slides.out 简单对比时间限 ...
- 实战:percona-xtrabackup 2.1.9 for mysql 5.6.19
----1.编译安装percona-xtrabackup yum install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr ...
- 仿hibernate,spring框架手动写
近期学习了hibernate底层技术和spring 的底层技术,认为非常不错,所以想分享下,要是说的不够具体.能够去下载资源自己查看下载链接 技术的体现是在实际中的.如今大体介绍一下吧 首先介绍hib ...
- nmq 提交到 npm
安装npm install nmq 源码:https://github.com/ronwe/nmq 此版本提供 pub/sub , 优化 pull
- oracle 下操作blob字段是否会产生大量redo
操作blob字段是否会产生大量redo,答案是不会.以下来做一个实验,測试数据库版本号是11.2.0.1.0: --创建一张表做測试之用 create table test_blob ( id n ...