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. [TypeScript] Query Properties with keyof and Lookup Types in TypeScript

    The keyof operator produces a union type of all known, public property names of a given type. You ca ...

  2. Office文档如何转换 PDF 转 DOC XLS

    1 使用Adobe Acrobat Pro,打开任意PDF都可以转换为XLSX格式(似乎没找到XLS)   2 如果你转换之后的东西无法打开,则先转换成DOC,然后再把DOC全选复制粘贴到XLS即可 ...

  3. Android调试工具_ Stetho

    Stetho是Facebook开源的一个Android平台调试工具. Stetho能实如今不root手机的情况下,通过Chrome查看App的布局,Sqlite,SharedPreference.Ne ...

  4. HDU 1272: 小希的迷宫(并查集)

    小希的迷宫 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  5. rand和srand的用法(转载)

    首先我们要对rand&srand有个总体的看法:srand初始化随机种子,rand产生随机数,下面将详细说明. rand(产生随机数)表头文件: #include<stdlib.h> ...

  6. Apache Hadoop 和Hadoop生态圈

    Apache Hadoop 和Hadoop生态圈 Hadoop是一个由Apache基金会所开发的分布式系统基础架构. 用户能够在不了解分布式底层细节的情况下.开发分布式程序.充分利用集群的威力进行快速 ...

  7. 使用OnScrollListener回调处理自己主动载入很多其它

    首先来分析下OnScrollListener的回调. new OnScrollListener() { boolean isLastRow = false; @Override public void ...

  8. 编程题:1. var person = '{name:"Lily",sex:"famale",age:24,country:"US"}';将person转换成JSON对象并便利每个属性值。

    /// <summary> /// Json工具类 /// </summary> public class JsonUtility { private static JsonU ...

  9. jackson实体为NULL或者为空不显示

    1.实体上 @JsonInclude(JsonInclude.Include.NON_NULL) 将该注解放在属性上,如果该属性为null则不参与序列化: 如果放在类上边,那对这个类的全部属性起作用 ...

  10. C++ pair(对组)用法(转)

    类模板:template <class T1, class T2> struct pair 参数:T1是第一个值的数据类型,T2是第二个值的数据类型. 功能:pair将一对值组合成一个值, ...