题目链接:Codeforces 417D Cunning Gena

题目大意:n个小伙伴。m道题目,每一个监视器b花费,给出n个小伙伴的佣金,所须要的监视器数,以及能够完毕的题目序号。

注意,这里仅仅要你拥有的监视器数量大于小伙伴须要的监视器数量就可以。

求最少花费多少金额能够解决全部问题。

解题思路:dp[i],i为一个二进制数。表示完毕这些题目的最小代价,可是这里要注意,由于有个监视器的数量。普通情况下要开一个二维的状态。可是2^20次方有一百万,再多一维的数组会超内存,所以我的做法是将每一个小伙伴依照监视器的数量从小到达排序,慢慢向上加。

#include <cstdio>
#include <cstring>
#include <set>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
const int N = (1<<20)+5;
const int M = 105;
const ll INF = 0x3f3f3f3f3f3f3f3f; struct state {
int s;
ll k, val;
}p[M];
int n, m;
ll b, dp[N]; bool cmp (const state& a, const state& b) {
return a.k < b.k;
} void init () {
memset(dp, -1, sizeof(dp)); scanf("%d%d", &n, &m);
cin >> b; int t, a;
for (int i = 0; i < n; i++) {
cin >> p[i].val >> p[i].k >> t;
p[i].s = 0;
for (int j = 0; j < t; j++) {
scanf("%d", &a);
p[i].s |= (1<<(a-1));
}
}
sort(p, p + n, cmp);
} ll solve () {
dp[0] = 0; int t = (1<<m)-1;
ll ans = INF;
for (int i = 0; i < n; i++) { for (int j = 0; j <= t; j++) {
if (dp[j] == -1) continue; int u = p[i].s | j; if (dp[u] == -1)
dp[u] = p[i].val + dp[j];
else
dp[u] = min(dp[u], p[i].val + dp[j]);
} if (dp[t] != -1)
ans = min(ans, dp[t] + p[i].k * b);
} return ans == INF ? -1 : ans;
} int main () {
init ();
cout << solve() << endl;
return 0;
}

Codeforces 417D Cunning Gena(状态压缩dp)的更多相关文章

  1. codeforces 417D. Cunning Gena 状压dp

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

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

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

  3. Codeforces C. A Simple Task(状态压缩dp)

    题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. Codeforces 4538 (状态压缩dp)Little Pony and Harmony Chest

    Little Pony and Harmony Chest 经典状态压缩dp #include <cstdio> #include <cstring> #include < ...

  5. hoj2662 状态压缩dp

    Pieces Assignment My Tags   (Edit)   Source : zhouguyue   Time limit : 1 sec   Memory limit : 64 M S ...

  6. POJ 3254 Corn Fields(状态压缩DP)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4739   Accepted: 2506 Descr ...

  7. [知识点]状态压缩DP

    // 此博文为迁移而来,写于2015年7月15日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102w6jf.html 1.前 ...

  8. HDU-4529 郑厂长系列故事——N骑士问题 状态压缩DP

    题意:给定一个合法的八皇后棋盘,现在给定1-10个骑士,问这些骑士不能够相互攻击的拜访方式有多少种. 分析:一开始想着搜索写,发现该题和八皇后不同,八皇后每一行只能够摆放一个棋子,因此搜索收敛的很快, ...

  9. DP大作战—状态压缩dp

    题目描述 阿姆斯特朗回旋加速式阿姆斯特朗炮是一种非常厉害的武器,这种武器可以毁灭自身同行同列两个单位范围内的所有其他单位(其实就是十字型),听起来比红警里面的法国巨炮可是厉害多了.现在,零崎要在地图上 ...

随机推荐

  1. 索引式优先队列(indexed priority queue)

    为了达到O(ElogV)的效率,需要对普利姆算法进行eager实现. 如果我们用java来做,jdk当中的priorityQueue并不能满足我们的要求. 因为我们需要进行一个对索引元素降key的操作 ...

  2. JS简单实现二级联动菜单

    <form method="post" action=""> 省/市:<select id="province" onch ...

  3. PostgreSQL远程连接配置管理/账号密码分配(解决:致命错误: 用户 "postgres" Ident 认证失败)

    问题:致命错误: 用户 "postgres" Ident 认证失败 说明:这个是由于没有配置远程访问且认证方式没改造成的,只需要更改使用账号密码认证即可. 解决:找到pg_hba. ...

  4. 2007 Audi A4 INSTRUMENT CLUSTER WIRING DIAGRAM

    BOSCH RB8 8E0920 951G I found the answer by myself...... Here is what it's work for me. GREEN CONNEC ...

  5. BTSync 2.0 Vs. 1.4 Folders

    Sync 2.0 supports boths new 2.0 folders and classic 1.4 folders, s o when you upgrade your Sync it w ...

  6. ASK,OOK,FSK,GFSK是什么

    http://www.21say.com/askookfskgfsk%E6%98%AF%E4%BB%80%E4%B9%88/ ASK是幅移键控调制的简写,例如二进制的,把二进制符号0和1分别用不同的幅 ...

  7. 读 Zepto 源码系列

    虽然最近工作中没有怎么用 zepto ,但是据说 zepto 的源码比较简单,而且网上的资料也比较多,所以我就挑了 zepto 下手,希望能为以后阅读其他框架的源码打下基础吧. 源码版本 本文阅读的源 ...

  8. MVC二级联动使用$.getJSON方法

    本篇使用jQuery的$.getJSON()实现二级联动.   □ View Models 1: namespace MvcApplication1.Models 2: { 3: public cla ...

  9. list去除重复数据

    在java里面要想去除list中的重复数据可以使用两种方式实现: 1. 循环list中的所有元素然后删除重复 public static List removeDuplicate(List list) ...

  10. apache基金会项目及甲骨文项目汇总

    Apache软件基金会 顶级项目 ▪ ActiveMQ ▪ Ant ▪ Apache HTTP Server ▪ APR ▪ Beehive ▪ Camel ▪ Cassandra ▪ Cayenne ...