【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的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- 树莓派搭建 Google TV
出处:http://my.oschina.net/funnky/blog/142067 树莓派搭建 Google TV 目录:[ - ] Google TV是啥玩意 ? 搭建我们自己的Google T ...
- jpa自定义条件分页查询
主要依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- strlen()函数对一个未初始化数组的处理
今天使用strlen时 ,发现一个问题,demo代码如下: #include <stdio.h> #include <stdlib.h> #include <string ...
- ES6重点知识点总结(2)
ES6重点知识点总结(2) call和apply的作用是什么?区别是什么? call和apply的功能基本相同,都是实现继承或者转换对象指针的作用: 唯一不通的是前者参数是罗列出来的,后者是存到数组中 ...
- Spring中的InitializingBean接口
InitializingBean接口为bean提供了初始化方法的方式,它只有afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候会执行该方法. 测试程序如下: impo ...
- 记一次BootStrap的使用
效果图如下: 一.简介: 什么是Bootstrap? Bootstrap 是一个用于快速开发 Web 应用程序和网站的前端框架. 什么是响应式布局? 引用一句Bootstrap的标题语 “Boots ...
- UML基础知识点
UML : unified Modeling Language 统一建模语言 1.对系统问题进行分析和建模 2.非专利的第三代建模和规约语言 3.UML是一种开放的方法.用于说明.可视化.构 ...
- HDU 2865
和上题一样,但K较大,不能直接用矩阵来写.这个矩阵必定是这个形式的. 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 分成对角线上元素B与非对角线上元素A k: 1 2 3 4 ... ...
- PyQt: LineEdit的智能输入提示
使用的的类是QtGui.QCompleter from PyQt4 import QtGui,QtCore str = QtCore.QStringList(['a','air','airbus']) ...
- Brute force Attack
1 Introduction A common threat that webdevelopers face is a password-guessing attack known as a brut ...