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的更多相关文章

  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. ASP.NET Core 奇淫技巧之动态WebApi

    一.前言 接触到动态WebApi(Dynamic Web API)这个词的已有几年,是从ABP框架里面接触到的,当时便对ABP的这个技术很好奇,后面分析了一波,也尝试过从ABP剥离一个出来作为独立组件 ...

  2. 【转】Linux下添加新硬盘,分区及挂载

    原文:http://blog.chinaunix.net/uid-25829053-id-3067619.html ------------------------------------------ ...

  3. srand rand 随机函数

    srand函数是随机数发生器的初始化函数.原型:voidsrand(unsigned int seed); srand和rand()配合使用产生伪随机数序列.rand函数在产生随机数前,需要系统提供的 ...

  4. iOS学习之动画效果的实现

    // //  ViewController.m //  UI-动画练习 // //  Created by jzq_mac on 15/7/22. //  Copyright (c) 2015年 jz ...

  5. 全栈JavaScript之路(十六)HTML5 HTMLDocument 类型的变化

    HTML5 扩展了 HTMLDocument, 添加了新的功能. 1.document.readState = 'loading' || 'complete'  //支持readyState 属性的浏 ...

  6. 浅谈JavaScript的面向对象程序设计(三)

    前面已经对JavaScript的面向对象程序设计作了简单的介绍,包括了对象的属性.对象的工厂模式.构造函数和原型等.通过介绍,这些创建对象的方法依然有不少优化和改进的地方. 组合使用构造函数模式和原型 ...

  7. 【小技能】如何检索苹果APP

    有时候要临时在PC上查询一下苹果APP的信息,但是又没有安装itunes软件,那么你可以在必应里面使用类似如下的语句,例如来搜索“aboboo site:itunes.apple.com”,就可以搜索 ...

  8. AWS携手上海嘉定政府推出首个联合孵化器 为创业公司拓展AWS云服务可用资源

    2014年10月17日 AWS Activate创业加速计划为中国创业公司提供各种支持,包含AWS全球和中国区服务抵扣券.培训和开发人员支持.同一时候,AWS携手上海嘉定政府成立首家联合孵化器,为创业 ...

  9. scikit-learn 机器学习工具

    1.http://scikit-learn.org/stable/        官网:关于scikit-learn介绍等 2. http://stackoverflow.com/questions/ ...

  10. leetcode 395. Longest Substring with At Least K Repeating Characters

    Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...