Cunning Gena CodeForces - 417D
Cunning Gena CodeForces - 417D
先将小伙伴按需要的监视器数量排序。然后ans[i][j]表示前i个小伙伴完成j集合内题目所需最少钱。那么按顺序枚举小伙伴,用ans[i-1][j]更新ans[i][j]和ans[i][j | 第i个小伙伴能完成题目的集合](更新后一种时答案要加上第i个小伙伴的费用)。
由于小伙伴已经按监视器数量排序了,对于每个枚举出的小伙伴i,可以试着将其作为最后一个要求助的小伙伴,那么此时监视器上花的钱就是这个小伙伴所需监视器数量*每个的费用,求助小伙伴费用就是ans[i][所有题目的集合],此时总费用就是这两者的总和。最终答案就是最小的枚举得到的总费用。
可以开滚动数组优化空间。
错误记录:45-47无效代码导致TLE
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- #include<vector>
- using namespace std;
- typedef long long LL;
- LL n,m1,b;
- struct A
- {
- LL x,k,v;
- bool operator<(const A& b) const
- {
- return k<b.k;
- }
- }aa[];
- LL ans[][];
- LL anss;
- int main()
- {
- LL i,j,k,t,tt,ii=;
- scanf("%I64d%I64d%I64d",&n,&m1,&b);
- for(i=;i<=n;i++)
- {
- scanf("%I64d%I64d%I64d",&aa[i].x,&aa[i].k,&tt);
- for(j=;j<=tt;j++)
- {
- scanf("%I64d",&t);
- //v[i].push_back(t);
- aa[i].v|=(<<(t-));
- }
- }
- sort(aa+,aa+n+);
- anss=0x3f3f3f3f3f3f3f3f;
- memset(ans,0x3f,sizeof(ans));
- ans[][]=;
- for(i=;i<n;i++)
- {
- ii^=;
- memset(ans[ii],0x3f,sizeof(ans[ii]));
- for(j=;j<(<<m1);j++)
- {
- ans[ii][j]=min(ans[ii][j],ans[ii^][j]);
- ans[ii][j|aa[i+].v]=min(ans[ii][j|aa[i+].v],ans[ii^][j]+aa[i+].x);
- }
- /*for(j=0;j<(1<<m1);j++)
- for(k=0;k<m1;k++)
- ans[ii][j]=min(ans[ii][j],ans[ii][j|(1<<k)]);*/
- anss=min(anss,ans[ii][(<<m1)-]+b*aa[i+].k);
- }
- if(anss!=0x3f3f3f3f3f3f3f3f)
- printf("%I64d",anss);
- else
- printf("-1");
- return ;
- }
Cunning Gena CodeForces - 417D的更多相关文章
- Codeforces 417D Cunning Gena(状态压缩dp)
题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...
- codeforces 417D. Cunning Gena 状压dp
题目链接 D. Cunning Gena time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 417 D. Cunning Gena
按monitor排序,然后状压DP... . D. Cunning Gena time limit per test 1 second memory limit per test 256 megaby ...
- 【codeforces 417D】Cunning Gena
[题目链接]:http://codeforces.com/problemset/problem/417/D [题意] 有n个人共同完成m个任务; 每个人有可以完成的任务集(不一定所有任务都能完成); ...
- FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena
告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...
- RCC 2014 Warmup (Div. 2) 蛋疼解题总结
A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #339 (Div. 2) B. Gena's Code 水题
B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...
- Codeforces Round #339 Div.2 B - Gena's Code
It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...
- [CodeForces - 614B] B - Gena's Code
B - Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There ...
随机推荐
- Bag-of-words模型、TF-IDF模型
Bag-of-words model (BoW model) 最早出现在NLP和IR(information retrieval)领域. 该模型忽略掉文本的语法和语序, 用一组无序的单词(words) ...
- centos No module named setuptools解决方案
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz tar zxvf setuptool ...
- UVA 4857 Halloween Costumes 区间背包
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- Deepin-安装vscode
安装方式有两种: 1.通过命令安装 sudo apt-get install vscode 2.通过deb或rpm包安装 我们是Debian系列的系统,所以用deb包,关于红帽系统,请使用rpm包. ...
- SQL - 创建一个学生表,要求有主键约束和非空约束
CREATE TABLE [dbo].[Student] ( [ID] [int] NOT NULL, [Name] [nchar](10) NOT NULL, [Age] [int] NOT NUL ...
- 项目实战之玩转div+css制作自己定义形状
项目需求 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...
- OTG识别原理
如图1所示,那个是Micro USB的母头,可以清晰看到有5pin,分别是(不分顺序):Vbus.GND.D+.D-.ID.当移动设备,类似手机.平板电脑等要支持OTG功能,就必须使用这个接口,而且电 ...
- 游戏server设计的一些感悟
Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Date:September 30 ...
- web.xml中的ServletContextListener
要想了解ServletContextListener,先看看web.xml中的<listener>配置. 一)web.xml中的内容载入顺序: 首先能够肯定的是,载入顺序与它们在 web. ...
- 【iOS开发】-NSString的扩展使用
第一:基本数据类型与字符串转换 //基本数据类型(int float,double char) 1)基本数据类型->NSString //1.int类型换换成字符串 int a = 88; NS ...