题目链接:http://codeforces.com/gym/101981/attachments

There are n heroes and m monsters living in an island. The monsters became very vicious these days,
so the heroes decided to diminish the monsters in the island. However, the i-th hero can only kill one
monster belonging to the set Mi. Joe, the strategist, has k bottles of magic potion, each of which can buff
one hero’s power and let him be able to kill one more monster. Since the potion is very powerful, a hero
can only take at most one bottle of potion.
Please help Joe find out the maximum number of monsters that can be killed by the heroes if he uses the
optimal strategy.

Input
The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 500) — the number of heroes, the number of
monsters and the number of bottles of potion.
Each of the next n lines contains one integer ti, the size of Mi, and the following ti integers
Mi,j (1 ≤ j ≤ ti), the indices (1-based) of monsters that can be killed by the i-th hero
(1 ≤ ti ≤ m, 1 ≤ Mi,j ≤ m).

Output
Print the maximum number of monsters that can be killed by the heroes.

Examples

standard input
3 5 2
4 1 2 3 5
2 2 5
2 1 2

standard output
4

standard input
5 10 2
2 3 10
5 1 3 4 6 10
5 3 4 6 8 9
3 1 9 10
5 1 3 6 7 10

standard output
7

题意:

有 $n$ 个勇士,$m$ 个怪物,现在告诉你每个勇士可以杀哪些怪物,每个勇士只能从中选择一只怪物将其杀死,

而 $n$ 个勇士中最多可以有 $k$ 个勇士能够多杀一只怪物。

求最多能杀死的怪物数目。

题解:

最大流。根据题目所给的数据,从勇士向怪物连边,流量上限均为 $1$。

源点连到每个勇士一条边,流量上限均为 $1$。源点连到另一个虚拟节点,流量上限为 $k$,该虚拟节点连向每个勇士,流量上限均为 $1$。

每个怪物连向汇点,流量上限均为 $1$。

求出最大流即为答案。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=*+;
struct Edge{
int u,v,c,f;
};
struct Dinic
{
int s,t; //源点汇点
vector<Edge> E;
vector<int> G[maxn];
void init(int l,int r)
{
E.clear();
for(int i=l;i<=r;i++) G[i].clear();
}
void addedge(int from,int to,int cap)
{
E.push_back((Edge){from,to,cap,});
E.push_back((Edge){to,from,,});
G[from].push_back(E.size()-);
G[to].push_back(E.size()-);
}
int dist[maxn],vis[maxn];
queue<int> q;
bool bfs() //在残量网络上构造分层图
{
memset(vis,,sizeof(vis));
while(!q.empty()) q.pop();
q.push(s);
dist[s]=;
vis[s]=;
while(!q.empty())
{
int now=q.front(); q.pop();
for(int i=;i<G[now].size();i++)
{
Edge& e=E[G[now][i]]; int nxt=e.v;
if(!vis[nxt] && e.c>e.f)
{
dist[nxt]=dist[now]+;
q.push(nxt);
vis[nxt]=;
}
}
}
return vis[t];
}
int dfs(int now,int flow)
{
if(now==t || flow==) return flow;
int rest=flow,k;
for(int i=;rest> && i<G[now].size();i++)
{
Edge &e=E[G[now][i]]; int nxt=e.v;
if(e.c>e.f && dist[nxt]==dist[now]+)
{
k=dfs(nxt,min(rest,e.c-e.f));
if(!k) dist[nxt]=; //剪枝,去掉增广完毕的点
e.f+=k; E[G[now][i]^].f-=k;
rest-=k;
}
}
return flow-rest;
}
int mf; //存储最大流
int maxflow()
{
mf=;
int flow=;
while(bfs()) while(flow=dfs(s,INF)) mf+=flow;
return mf;
}
}dinic;
int n,m,k;
int main()
{
scanf("%d%d%d",&n,&m,&k);
dinic.s=, dinic.t=n+m+;
dinic.addedge(dinic.s,n+m+,k);
for(int i=,t;i<=n;i++)
{
dinic.addedge(dinic.s,i,);
dinic.addedge(n+m+,i,);
scanf("%d",&t);
for(int j=,k;j<=t;j++)
{
scanf("%d",&k);
dinic.addedge(i,n+k,);
}
}
for(int i=;i<=m;i++) {
dinic.addedge(n+i,dinic.t,);
}
printf("%d\n",dinic.maxflow());
}

Gym 101981I - Magic Potion - [最大流][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem I]的更多相关文章

  1. Gym - 101981I The 2018 ICPC Asia Nanjing Regional Contest I.Magic Potion 最大流

    题面 题意:n个英雄,m个怪兽,第i个英雄可以打第i个集合里的一个怪兽,一个怪兽可以在多个集合里,有k瓶药水,每个英雄最多喝一次,可以多打一只怪兽,求最多打多少只 n,m,k<=500 题解:显 ...

  2. Gym - 101981K The 2018 ICPC Asia Nanjing Regional Contest K.Kangaroo Puzzle 暴力或随机

    题面 题意:给你1个20*20的格子图,有的是障碍有的是怪,你可以每次指定上下左右的方向,然后所有怪都会向那个方向走, 如果2个怪撞上了,就融合在一起,让你给不超过5w步,让所有怪都融合 题解:我们可 ...

  3. Gym - 101981M The 2018 ICPC Asia Nanjing Regional Contest M.Mediocre String Problem Manacher+扩增KMP

    题面 题意:给你2个串(长度1e6),在第一个串里找“s1s2s3”,第二个串里找“s4”,拼接后,是一个回文串,求方案数 题解:知道s1和s4回文,s2和s3回文,所以我们枚举s1的右端点,s1的长 ...

  4. Gym - 101981G The 2018 ICPC Asia Nanjing Regional Contest G.Pyramid 找规律

    题面 题意:数一个n阶三角形中,有多少个全等三角形,n<=1e9 题解:拿到题想找规律,手画开始一直数漏....,最后还是打了个表 (打表就是随便定个点为(0,0),然后(2,0),(4,0), ...

  5. Gym - 101981D The 2018 ICPC Asia Nanjing Regional Contest D.Country Meow 最小球覆盖

    题面 题意:给你100个三维空间里的点,让你求一个点,使得他到所有点距离最大的值最小,也就是让你找一个最小的球覆盖掉这n个点 题解:红书模板题,这题也因为数据小,精度也不高,所以也可以用随机算法,模拟 ...

  6. Gym - 101981J The 2018 ICPC Asia Nanjing Regional Contest J.Prime Game 计数

    题面 题意:1e6的数组(1<a[i]<1e6),     mul (l,r) =l × (l+1) ×...× r,  fac(l,r) 代表 mul(l,r) 中不同素因子的个数,求s ...

  7. Gym - 101981A The 2018 ICPC Asia Nanjing Regional Contest A.Adrien and Austin 简单博弈

    题面 题意:一堆有n个石子,编号从1⋯N排成一列,两个人Adrien 和Austin玩游戏,每次可以取1⋯K个连续编号的石子,Adrien先手,谁不能取了则输 题解:k==1时,显然和n奇偶相关,当k ...

  8. Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]

    题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices s ...

  9. Gym 101981J - Prime Game - [数学题][线性筛+分解质因数][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem J]

    题目链接:http://codeforces.com/gym/101981/attachments 题意: 令 $mul(l,r) = \prod_{i=l}^{r}a_i$,且 $fac(l,r)$ ...

随机推荐

  1. codevs 2033 邮票

    洛谷 P2725 邮票 Stamps codevs 2033 邮票 题目链接 http://codevs.cn/problem/2033/ https://www.luogu.org/problemn ...

  2. 深入理解Linux内存分配

    深入理解Linux内存分配 为了写一个用户层程序,你也许会声明一个全局变量,这个全局变量可能是一个int类型也可能是一个数组,而声明之后你有可能会先初始化它,也有可能放在之后用到它的时候再初始化.除此 ...

  3. k8s namespace/volume

    https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/ 只挑个人感觉使用较多/比较重要的点来说 ...

  4. 6. 从Encoder-Decoder(Seq2Seq)理解Attention的本质

    1. 语言模型 2. Attention Is All You Need(Transformer)算法原理解析 3. ELMo算法原理解析 4. OpenAI GPT算法原理解析 5. BERT算法原 ...

  5. 基于jQuery 3D旋转明星人物展示特效

    分享一款基于jQuery 3D旋转明星人物展示特效.这是一款来自百度换肤活动的明星旋转展示效果.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=&quo ...

  6. ubuntu Ros环境halcon的一个程序

    这个首先并不是我一边做实验一遍记录的,而是我做完成以后才想起来做个分享的,所以中途遇到的很多问题,并没有来得及记录下来,现在写的这些都是后话了 首先呢!我们不需要在ROS下写halcon的程序也是可以 ...

  7. 怎样写一个PC端使用的操盘手软件(用来买卖股票,查看报表,行情)

    我们想写一个操盘手软件,对于操盘而言,首先是快,然后是资料尽可能丰富,最好能看到行情,报表什么的.只是windows上写软件看似基础,实际上都不怎么好弄,用C++开发确实可以实现所有功能,估计光研发费 ...

  8. ScheduledThreadPoolExecutor实现原理

    ScheduledThreadPoolExecutor实现原理 博客分类: concurrency java   自jdk1.5开始,Java开始提供ScheduledThreadPoolExecut ...

  9. Mixed Content: xxx This request has been blocked; the content must be served over HTTPS.

    在升级https的过程中,出现如下问题: Mixed Content: The page at 'https://www.xxx.com/denglu.html' was loaded over HT ...

  10. Mysql Window 解压版卸载

    windows如何彻底卸载mysql 如何彻底删除mysql 1.首先在windows服务中将mysql服务删掉,使用命令 sc delete mysql 2.在控制面板中卸载掉mysql. 3.清理 ...