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

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<vector>
  5. using namespace std;
  6. typedef long long LL;
  7. LL n,m1,b;
  8. struct A
  9. {
  10. LL x,k,v;
  11. bool operator<(const A& b) const
  12. {
  13. return k<b.k;
  14. }
  15. }aa[];
  16. LL ans[][];
  17. LL anss;
  18. int main()
  19. {
  20. LL i,j,k,t,tt,ii=;
  21. scanf("%I64d%I64d%I64d",&n,&m1,&b);
  22. for(i=;i<=n;i++)
  23. {
  24. scanf("%I64d%I64d%I64d",&aa[i].x,&aa[i].k,&tt);
  25. for(j=;j<=tt;j++)
  26. {
  27. scanf("%I64d",&t);
  28. //v[i].push_back(t);
  29. aa[i].v|=(<<(t-));
  30. }
  31. }
  32. sort(aa+,aa+n+);
  33. anss=0x3f3f3f3f3f3f3f3f;
  34. memset(ans,0x3f,sizeof(ans));
  35. ans[][]=;
  36. for(i=;i<n;i++)
  37. {
  38. ii^=;
  39. memset(ans[ii],0x3f,sizeof(ans[ii]));
  40. for(j=;j<(<<m1);j++)
  41. {
  42. ans[ii][j]=min(ans[ii][j],ans[ii^][j]);
  43. ans[ii][j|aa[i+].v]=min(ans[ii][j|aa[i+].v],ans[ii^][j]+aa[i+].x);
  44. }
  45. /*for(j=0;j<(1<<m1);j++)
  46. for(k=0;k<m1;k++)
  47. ans[ii][j]=min(ans[ii][j],ans[ii][j|(1<<k)]);*/
  48. anss=min(anss,ans[ii][(<<m1)-]+b*aa[i+].k);
  49. }
  50. if(anss!=0x3f3f3f3f3f3f3f3f)
  51. printf("%I64d",anss);
  52. else
  53. printf("-1");
  54. return ;
  55. }

Cunning Gena CodeForces - 417D的更多相关文章

  1. Codeforces 417D Cunning Gena(状态压缩dp)

    题目链接:Codeforces 417D Cunning Gena 题目大意:n个小伙伴.m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号. 注意,这里仅仅 ...

  2. codeforces 417D. Cunning Gena 状压dp

    题目链接 D. Cunning Gena time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. Codeforces 417 D. Cunning Gena

    按monitor排序,然后状压DP... . D. Cunning Gena time limit per test 1 second memory limit per test 256 megaby ...

  4. 【codeforces 417D】Cunning Gena

    [题目链接]:http://codeforces.com/problemset/problem/417/D [题意] 有n个人共同完成m个任务; 每个人有可以完成的任务集(不一定所有任务都能完成); ...

  5. FZU 2165 v11(最小重复覆盖)+ codeforces 417D Cunning Gena

    告诉你若干个(<=100)武器的花费以及武器能消灭的怪物编号,问消灭所有怪物(<=100)的最小花费...当然每个武器可以无限次使用,不然这题就太水了╮(╯▽╰)╭ 这题当时比赛的时候连题 ...

  6. RCC 2014 Warmup (Div. 2) 蛋疼解题总结

    A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. 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 ...

  8. 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 ...

  9. [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 ...

随机推荐

  1. Bag-of-words模型、TF-IDF模型

    Bag-of-words model (BoW model) 最早出现在NLP和IR(information retrieval)领域. 该模型忽略掉文本的语法和语序, 用一组无序的单词(words) ...

  2. centos No module named setuptools解决方案

    wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz tar zxvf setuptool ...

  3. UVA 4857 Halloween Costumes 区间背包

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  4. Deepin-安装vscode

    安装方式有两种: 1.通过命令安装 sudo apt-get install vscode 2.通过deb或rpm包安装 我们是Debian系列的系统,所以用deb包,关于红帽系统,请使用rpm包. ...

  5. SQL - 创建一个学生表,要求有主键约束和非空约束

    CREATE TABLE [dbo].[Student] ( [ID] [int] NOT NULL, [Name] [nchar](10) NOT NULL, [Age] [int] NOT NUL ...

  6. 项目实战之玩转div+css制作自己定义形状

    项目需求 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/diss ...

  7. OTG识别原理

    如图1所示,那个是Micro USB的母头,可以清晰看到有5pin,分别是(不分顺序):Vbus.GND.D+.D-.ID.当移动设备,类似手机.平板电脑等要支持OTG功能,就必须使用这个接口,而且电 ...

  8. 游戏server设计的一些感悟

    Author:Echo Chen(陈斌) Email:chenb19870707@gmail.com Blog:Blog.csdn.net/chen19870707 Date:September 30 ...

  9. web.xml中的ServletContextListener

    要想了解ServletContextListener,先看看web.xml中的<listener>配置. 一)web.xml中的内容载入顺序: 首先能够肯定的是,载入顺序与它们在 web. ...

  10. 【iOS开发】-NSString的扩展使用

    第一:基本数据类型与字符串转换 //基本数据类型(int float,double char) 1)基本数据类型->NSString //1.int类型换换成字符串 int a = 88; NS ...