Human life FZU - 2295 最大权闭合子图(第一次遇到被教育了)
Xzz is playing a MMORPG "human life".
In this game, there are N different skills. Some skills may base on another skill.
Learning skill will cost Xzz some money.
And there are M different jobs. If Xzz's skills satisfy the job's requirement, then Xzz can get this job, and get some money.
But some jobs are conflict, some Xzz can't get the job at same time.
There are K pairs of jobs are conflict.
Now Xzz want to know the money he can get at the most,can you help him.
Input
First line of the input file contains an integer T(0 < T ≤ 10) that indicates how many cases of inputs are there.
The description of each case is given below:
The first line of each input case contains number N, M, K. N <= 100, M <= 50, K <= 5.
Then follow N lines. In ith line the first two number ? ,? , means learning skill i const vi , skill i base on another ni skills. The last ni number aij means before learning skill i Xzz need to learn skill aij. 0 ≤ vi ≤ 1000, 0 ≤ ni ≤ N
Then follow M lines. In ith line the first two number wi, mi , means job i earn wi, jobs i base on mi skills. The last mi number bij means get job i need to learn skill bij. 0 ≤ wi ≤ 1000, 0 ≤ mi ≤ M
Then follow K lines. In ith line the first two number ci, di, means job ci conflict with job di.
Output
The description of output for each test case is given below:
The first line of the output for each test case contains number answer, the maximum money Xzz can get.
Sample Input
2
5 2 0
1 0
1 1 1
1 0
1 0
1 1 4
10 2 2 3
8 2 3 5
5 2 1
1 0
1 1 1
1 0
1 0
1 1 4
10 2 2 3
8 2 3 5
1 2
Sample Output
13
7 今天组队训练,这个我负责的图论部分没有写出来 难受啊
今天想拿网络流 流过去结果建图不知道该怎么建图 流也流不对
结束后才知道这就是最大权闭合子图的板子题目
唉 图论的基本套路我都还没有掌握 难受啊 今天然后晚上认真的学习了最大权闭合子图 点击这里学习最大权闭合子图 博主很良心讲的非常好 然后下面这一题就稍微的改动了一下
一开始我还在想k如何处理 ,后来学长告诉我k最大为5 直接枚举所有情况就好了 然后就是基本的建图操作
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <algorithm>
#include <set>
#include <iostream>
#include <map>
#include <stack>
#include <string>
using namespace std;
#define pi acos(-1.0)
#define eps 1e-6
#define fi first
#define se second
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define bug printf("******")
#define mem(a,b) memset(a,b,sizeof(a))
#define fuck(x) cout<<"["<<x<<"]"<<endl
#define f(a) a*a
#define san(n,m) scanf("%d%d",&n,&m)
#define FIN freopen("in.txt","r",stdin)
#define lowbit(x) x&-x
#pragma comment (linker,"/STACK:102400000,102400000")
using namespace std;
const int maxn = ;
typedef long long LL;
const int MX = ;
const int MXE = * MX * MX;
const LL INFLL = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x3f3f3f;
struct MaxFlow {
struct Edge {
int v, nxt;
LL w;
} E[MXE];
int tot, num, s, t;
int head[MX];
void init() {
memset (head, -, sizeof (head) );
tot = ;
}
void add (int u, int v, LL w) {
E[tot] = (Edge) {
v, head[u], w
};
head[u] = tot++;
E[tot] = (Edge) {
u, head[v],
};
head[v] = tot++;
}
int d[MX], vis[MX], gap[MX];
void bfs() {
memset (d, , sizeof (d) );
memset (gap, , sizeof (gap) );
memset (vis, , sizeof (vis) );
queue<int>q;
q.push (t);
vis[t] = ;
while (!q.empty() ) {
int u = q.front();
q.pop();
for (int i = head[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (!vis[v]) {
d[v] = d[u] + ;
gap[d[v]]++;
q.push (v);
vis[v] = ;
}
}
}
}
int last[MX];
LL dfs (int u, LL f) {
if (u == t) return f;
LL sap = ;
for (int i = last[u]; ~i; i = E[i].nxt) {
int v = E[i].v;
if (E[i].w > && d[u] == d[v] + ) {
last[u] = i;
LL tmp = dfs (v, min (f - sap, E[i].w) );
E[i].w -= tmp;
E[i ^ ].w += tmp;
sap += tmp;
if (sap == f) return sap;
}
}
if (d[s] >= num) return sap;
if (! (--gap[d[u]]) ) d[s] = num;
++gap[++d[u]];
last[u] = head[u];
return sap;
}
LL solve (int st, int ed, int n) {
LL flow = ;
num = n;
s = st;
t = ed;
bfs();
memcpy (last, head, sizeof (head) );
while (d[s] < num) flow += dfs (s, INFLL);
return flow;
}
} F;
int t, n, m, k, vis[];
struct node {
int val, n;
int num[];
} a[], b[];
struct node1 {
int x, y;
} p[maxn];
int main() {
scanf("%d", &t);
while(t--) {
scanf("%d%d%d", &n, &m, &k);
for (int i = ; i <= n ; i++) {
scanf("%d%d", &a[i].val, &a[i].n);
for (int j = ; j < a[i].n ; j++) scanf("%d", &a[i].num[j]);
}
for (int i = ; i <= m ; i++) {
scanf("%d%d", &b[i].val, &b[i].n);
for (int j = ; j < b[i].n ; j++) scanf("%d", &b[i].num[j]);
}
for (int i = ; i < k ; i++) scanf("%d%d", &p[i].x, &p[i].y);
int st = , ed = n + m + ;
LL ans = ;
for (int i = ; i < ( << k) ; i++) {
LL sum = ;
F.init();
memset(vis, , sizeof(vis));
for (int j = ; j < k ; j++) {
if (vis[p[j].x] && vis[p[j].y] ) continue;
if ((i >> j) & ) vis[p[j].y] = ;
else vis[p[j].x] = ;
}
for (int j = ; j <= m ; j++) {
if (vis[j]) continue;
sum += 1LL * b[j].val;
F.add(st, j, b[j].val);
for (int p = ; p < b[j].n ; p++) F.add(j, m + b[j].num[p], INF);
}
for (int j = ; j <= n ; j++) {
F.add(m + j, ed, a[j].val);
for (int p = ; p < a[j].n ; p++) F.add(m + j, m + a[j].num[p], INF);
}
LL temp = F.solve(st, ed, n + m + );
ans = max(ans, sum - temp);
}
printf("%lld\n", ans);
}
return ;
}
Human life FZU - 2295 最大权闭合子图(第一次遇到被教育了)的更多相关文章
- FZU - 2295 Human life (最大权闭合子图)
题目链接 FZU - 2295 Human life 题目分析 题意:你在玩一个游戏,在其中你可以通过学习一些技能,但是学习某些技能之前,可能还要学习一些其他的技能,并且学习任何技能都有一定的花费: ...
- FZU - 2295 Human life:网络流-最大权闭合子图-二进制优化-第九届福建省大学生程序设计竞赛
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 http://acm.fzu.edu.cn/problem.php?pid=2295 htt ...
- BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)
题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...
- HDU 3879 Base Station(最大权闭合子图)
经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...
- [BZOJ 1497][NOI 2006]最大获利(最大权闭合子图)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1497 分析: 这是在有向图中的问题,且边依赖于点,有向图中存在点.边之间的依赖关系可以 ...
- HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4971 Description There's a company with several ...
- HDU5855 Less Time, More profit(最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...
- HDU5772 String problem(最大权闭合子图)
题目..说了很多东西 官方题解是这么说的: 首先将点分为3类 第一类:Pij 表示第i个点和第j个点组合的点,那么Pij的权值等于w[i][j]+w[j][i](表示得分) 第二类:原串中的n个点每个 ...
- SCU3109 Space flight(最大权闭合子图)
嗯,裸的最大权闭合子图. #include<cstdio> #include<cstring> #include<queue> #include<algori ...
随机推荐
- 【转载】IOS之禁用UIWebView的默认交互行为
原文地址 :IOS之禁用UIWebView的默认交互行为 http://my.oschina.net/hmj/blog/111344 UIKit提供UIWebView组件,允许开发者在App中嵌入We ...
- markdown语法介绍
1. 标题类 每级标题用"# title"表示,共支持6级标题: 2. 段落类 1.建议用换行符控制: 2.用"<p></p>"控制: ...
- opencv-学习笔记(6)图像梯度Sobel以及canny边缘检测
opencv-学习笔记(6)图像梯度Sobel以及canny边缘检测 这章讲了 sobel算子 scharr算子 Laplacion拉普拉斯算子 图像深度问题 Canny检测 图像梯度 sobel算子 ...
- 欢迎来怼-Alpha周(2017年10月19)贡献分配规则和分配结果
.从alpha周(2017年10月19日开始的2周)开始,提高贡献分比重. 贡献分 : 团队分 = 1 : 5 教师会在核算每位同学总分时按比例乘以系数. 每位同学带入团队贡献分10分,如果团队一共7 ...
- Thunder团队第五周 - Scrum会议1
Scrum会议1 小组名称:Thunder 项目名称:i阅app Scrum Master:杨梓瑞 工作照片: 邹双黛在照相,所以图片中没有该同学. 参会成员: 王航:http://www.cnblo ...
- java — 垃圾回收
1. 垃圾回收的意义 在java中,当没有对象指向原先分配给某个对象的内存的时候,这片内存就变成了垃圾,JVM的一个系统级线程就会自动释放这个内存块,垃圾回收意味着程序不再需要的对象是“无用的信息”, ...
- lintcode-185-矩阵的之字型遍历
185-矩阵的之字型遍历 给你一个包含 m x n 个元素的矩阵 (m 行, n 列), 求该矩阵的之字型遍历. 样例 对于如下矩阵: [ [1, 2, 3, 4], [5, 6, 7, 8], [9 ...
- 编译android6.0错误recipe for target 'out/host/linux-x86/obj/lib/libart.so' failed
转自:http://blog.csdn.net/ztguang/article/details/52856076 trip: libpagemap_32 (out/target/product/xx/ ...
- JavaScript中setInterval常见的问题(setInterval第一个参数加引号与不加引号区别)
- 从Mysql某一表中随机读取n条数据的SQL查询语句
若要在i ≤ R ≤ j 这个范围得到一个随机整数R ,需要用到表达式 FLOOR(i + RAND() * (j – i + 1)).例如, 若要在7 到 12 的范围(包括7和12)内得到一个随机 ...