记忆花搜索   dp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#define FFI freopen("in.txt", "r", stdin)
#define maxn 1010
#define INF 0x3f3f3f3f
#define inf 1000000000
#define mod 1000000007
#define ULL unsigned long long
#define LL long long
#define _setm(houge) memset(houge, INF, sizeof(houge))
#define _setf(houge) memset(houge, -1, sizeof(houge))
#define _clear(houge) memset(houge, 0, sizeof(houge))
using namespace std; int t, n, m, ca;
int pro[25], _cost[55], g[55][55];
LL nee[25], pre[55];
bool vis[55];
int k[25], q[25][55];
map <LL, int> pp; LL dfs(int u) {
if(vis[u]) return pre[u];
vis[u] = 1;
pre[u] |= 1LL << u;
for(int i = 0; i < m; ++ i) {
if(g[u][i]) {
pre[u] |= dfs(i);
}
}
return pre[u];
} int DP(LL cur) {
if(pp.count(cur)) return pp[cur];
int dd = 0, cc = 0;
for(int i = 0; i < n; ++ i) {
if((nee[i] & cur) == nee[i]) {
dd += pro[i];
}
}
for(int i = 0; i < m; ++ i) {
if((cur & (1LL << i))) {
cc += _cost[i];
}
}
pp[cur] = dd-cc;
for(int i = 0; i < n; ++ i) {
if((nee[i] & cur) != nee[i]) {
pp[cur] = max(pp[cur], DP(cur|nee[i]));
}
}
return pp[cur];
} int main () {
// FFI;
scanf("%d", &t);
ca = 0;
while(t --) {
scanf("%d%d", &n, &m);
_clear(nee);
pp.clear();
for(int i = 0; i < n; ++ i) {
scanf("%d", &pro[i]);
}
for(int i = 0; i < m; ++ i) {
scanf("%d", &_cost[i]);
}
for(int i = 0; i < n; ++ i) {
scanf("%d", &k[i]);
for(int j = 0; j < k[i]; ++ j) {
scanf("%d", &q[i][j]);
}
}
for(int i = 0; i < m; ++ i) {
for(int j = 0; j < m; ++ j) {
scanf("%d", &g[i][j]);
}
}
_clear(pre);
_clear(vis);
for(int i = 0; i < m; ++ i) {
if(!vis[i]) {
dfs(i);
}
}
for(int i = 0; i < n; ++ i) {
for(int j = 0; j < k[i]; ++ j) {
nee[i] |= pre[q[i][j]];
}
}
printf("Case #%d: %d\n", ++ ca, DP(0));
}
return 0;
}

  

hdu 4971的更多相关文章

  1. HDU 4971 (最小割)

    Problem A simple brute force problem (HDU 4971) 题目大意 有n个项目和m个问题,完成每个项目有对应收入,解决每个问题需要对应花费,给出每个项目需解决的问 ...

  2. HDU 4971 A simple brute force problem.

    A simple brute force problem. Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged o ...

  3. hdu - 4971 - A simple brute force problem.(最大权闭合图)

    题意:n(n <= 20)个项目,m(m <= 50)个技术问题,做完一个项目能够有收益profit (<= 1000),做完一个项目必须解决对应的技术问题,解决一个技术问题须要付出 ...

  4. HDU 4971 - A simple brute force problem【最大权闭合图】

    有n(20)个工程,完成每个工程获得收益是p[i],m(50)个需要解决的难题,解决每个难题花费是c[i] 要完成第i个工程,需要先解决ki个问题,具体哪些问题,输入会给出 每个难题之间可能有依赖关系 ...

  5. 【最小割】HDU 4971 A simple brute force problem.

    说是最大权闭合图.... 比赛时没敢写.... 题意 一共同拥有n个任务,m个技术 完毕一个任务可盈利一些钱,学习一个技术要花费钱 完毕某个任务前须要先学习某几个技术 可是可能在学习一个任务前须要学习 ...

  6. hdu 4971/ 2014多校/最大权闭合图

    题意:n个项目(每一个相应获得一定价值).m个技术问题(每一个须要支出一定价值),每一个项目必须要攻克若干个技术问题.技术难题之间有拓扑关系. 关键是建图.一看,第一感觉就是最大权闭合图,马上建好了图 ...

  7. hdu 4971 多校10最大权闭合图

    /* 很明显的最大权闭合图题 */ #include<stdio.h> #include<string.h> #include<queue> using names ...

  8. 漫话最小割 part1

    codeforces 724D [n个城市每个城市有一个特产的产出,一个特产的最大需求.当i<j时,城市i可以运最多C个特产到j.求所有城市可以满足最大的需求和] [如果直接最大流建图显然会T. ...

  9. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

随机推荐

  1. checkbox设置复选框的只读效果不让用户勾选

    在Web开发中,有时候需要显示一些复选框(checkbox),表明这个地方是可以进行勾选操作的,但是有时候是只想告知用户"这个地方是可以进行勾选操作的"而不想让用户在此处勾选(比如 ...

  2. easyui实现增删改查

    陈旧的开发模式 美工(ui工程师:出一个项目模型) java工程师:将原有的html转成jsp,动态展示数据 缺点: 客户需要调节前端的展示效果 解决:由美工去重新排版,重新选色. 前后端分离: 前端 ...

  3. 查看本机的ip地址

    ifconfig可以查看本机的ip地址:inet addr:10.108.104.185

  4. vue的使用配置

    我的编辑器是webstorm,虽然占内容占资源, 但是用起来很方便, 刚开始接触的时候就是用这个软件,很喜欢. vue的教程 1.http://www.jianshu.com/p/5ba253651c ...

  5. phpStrom+xdebug调试php

    1>xdebug下载 1.1>xdebug官网可以根据phpinfo()源代码来提供对应版本的xdebug,地址:https://xdebug.org/wizard.php 如下截图 1. ...

  6. Navicat Premium 12破解(转载)

    一.Navicat Premium 12下载 Navicat Premium 12是一套数据库开发管理工具,支持连接 MySQL.Oracle等多种数据库,可以快速轻松地创建.管理和维护数据库. Na ...

  7. virsh 命令

    virsh是用与管理虚拟化环境中的客户机和Hypervisor的命令行工具,与virt-manager等工具类似,也是调用libvirt API来实现虚拟化的管理. 在使用virsh命令行进行虚拟化管 ...

  8. 微信小程序request请求动态获取数据

    微信小程序开发文档链接 1 后台代码: clickButton:function(){ var that = this; wx.request({ url: 'http://localhost:909 ...

  9. Java:Md5加密

    文章来源:https://www.cnblogs.com/hello-tl/p/9139334.html import java.security.MessageDigest; public clas ...

  10. Android API Guides 安卓API指导----第一部分:Introduction(介绍)

    第一部分: Introduction(介绍) 目录包含:APP  Fundamentals     (应用程序基础) Device   Compatibility(设备兼容性) System Perm ...