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 ...
随机推荐
- [转]JavaEE开发基础
JavaEE开发基础 1 JavaEE简介 Java平台有三个版本,分别是JavaSE(Java Platform, Standard Edition),JavaEE(Java Platform, E ...
- DWR(AJAX)+Highcharts绘制曲线图,饼图
基本需求: 1. 在前台会用DWR框架(或者AJAX)调用Java后台代码获取要在Hightcharts展示的数据 2. 了解JSON(JavaScript Object Notation)的格式 3 ...
- ASP.NET Web Pages - 教程
ASP.NET Web Pages - 教程 ASP.NET 是一个使用 HTML.CSS.JavaScript 和服务器脚本创建网页和网站的开发框架. ASP.NET 支持三种不同的开发模式:Web ...
- react-redux 之 provider 和 connect
1.Provider 提供的是一个顶层容器的作用,实现store的上下文传递 2.connect 可以把state和dispatch绑定到react组件,使得组件可以访问到redux的数据 react ...
- Linux-github 搭建静态博客
1.在Github上创建一个新的Repository 到你的github上 https://github.com去create a new repository命名为 github.myblog 2. ...
- Qt 调用 Java 方法笔记
Qt 调用 Java 方法笔记 假设遇到相似的错误: error: undefined reference to '_jstring* QAndroidJniObject::callStaticMet ...
- C语言-- static 全局使用示例
C语言-- static 全局使用示例 前言:看到很多使用Objective-C开发IOS的大牛,有时候会使用static全局变量,相比之下,我却很少用这个,从而很少对其有着比较有实质意义的理解,甚 ...
- JNI/NDK开发指南(2)
1.生成动态库.so,存放于手机的system/lib/中(APP怎样将.so存入该文件夹,奇怪?????),Java层调用JNI的类会运行静态代码System.loadLibrary("* ...
- A Simple Example About Privileged Methods in JavaScript
Douglas Crockford classified the "class methods" in JavaScript into three types: private, ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) E. Prairie Partition 二分+贪心
E. Prairie Partition It can be shown that any positive integer x can be uniquely represented as x = ...