【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- JavaScript学习笔记(第二天)
数组 为什么要学习数组 之前学习的数据类型,只能存储一个值(比如:Number/String.我们想存储班级中所有学生的姓名,此时该如何存储? 数组的概念 所谓数组,就是将多个元素(通常是同一类型)按 ...
- docker 镜像的导入导出
今天使用docker部署asp.net core应用程序时,发现当我们做好基础镜像之后需要把镜像导出到正式环境,因此学习了一下如何从docker中导出镜像: 1.首先通过docker images命令 ...
- 2019-03-19 SQL Server简单存储过程的创建 删除 执行
--创建名为 Get 的有输入参数的存储过程 create proc Get --设置默认值 @TrustId int ='001' as begin select * from [DealStruc ...
- 2019-03-18 使用Request POST获取CNABS网站上JSON格式的表格数据,并解析出来用pymssql写到SQL Server中
import requests import pymssql url = 'https://v1.cn-abs.com/ajax/ChartMarketHandler.ashx' headers = ...
- Nuxt开发经验分享
Nuxt开发经验分享 本文章基于starter-template模板进行讲解,面向有vue-cli开发经验的宝宝 vue init nuxt-community/starter-template ...
- 使用malloc分别分配2KB的空间,然后用realloc调整为6KB的内存空间,打印指针地址
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<malloc.h> i ...
- WPF错误:必须使“Property”具有非 null 值。
这个问题一般出如今Triggers中Property指定的类型为Nullable. 解决的方法就是用DataTrigger取代Trigger, 然后用Binding+Converter转换为详细非Nu ...
- VS 2013+Qt 5.4.1
Qt应用能够用Qt Creator开发,也能够使用Visual Studio. 我之前一直用Qt Creator.也始终认为这是最好的选择.只是有人偏爱Visual Studio,我也由于工作须要,要 ...
- 除了信号触发线程与接收者线程相同的情况能直接调用到slot,其它情况都依赖事件机制(解决上面代码收不到信号的问题其实很简单,在线程的run();函数中添加一个事件循环就可以了,即加入一句exec();),信号槽不就是一个回调函数嘛
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { pThreadCon = new CSerialThread ...
- select into in mysql
http://stackoverflow.com/questions/16809393/select-into-in-mysql Use the CREATE TABLE SELECT syntax. ...