PKU 3281 Dining
来源:互联网 发布:淘宝的购物评级怎么涨 编辑:程序博客网 时间:2024/06/16 01:28
题目链接:
http://poj.org/problem?id=3281
题解:
Dinic模板 关键是怎么建图。但是自己比较蛇皮的只建了一只牛的图,到现在还没怎么明白为什么要建两只牛。
代码:
#include <cmath>#include <map>#include <vector>#include <queue>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;#define inf 0x7fffffff#define met(a,b) memset(a,b,sizeof(a))const int maxn =1000+10;int mp[maxn][maxn];int dis[maxn];int s,t;int bfs(){ queue<int>q; met(dis,0); dis[s]=1; q.push(s); while(!q.empty()) { int d=q.front(); q.pop(); for(int i=s;i<=t;i++) { if(!dis[i]&&mp[d][i]) { dis[i]=dis[d]+1; q.push(i); } } } return dis[t];}int dfs(int pos,int flow){ if(pos==t) return flow; int temp=flow; for(int i=0;i<=t&&temp;i++) { if(dis[i]==dis[pos]+1&&mp[pos][i]) { int a=dfs(i,min(temp,mp[pos][i])); mp[pos][i]-=a; mp[i][pos]+=a; temp-=a; } } return flow-temp;}int Dinic(){ int ans=0,temp=0; while(bfs()) { while(temp=dfs(s,inf)) ans+=temp; } return ans;}int main(){ int N,F,D; scanf("%d%d%d",&N,&F,&D); s=0,t=2*N+F+D+1; for(int i=1;i<=N;i++) { int f,d; scanf("%d%d",&f,&d); for(int j=0;j<f;j++) { int x; scanf("%d",&x); x+=2*N; mp[x][i]=1; mp[s][x]=1; } for(int j=0;j<d;j++) { int x; scanf("%d",&x); x+=2*N+F; mp[i+N][x]=1; mp[x][t]=1; } } for(int i=1;i<=N;i++) mp[i][i+N]=1; printf("%d\n",Dinic());}
阅读全文
0 0
- PKU 3281 Dining
- 【PKU 3281】Dining(构图+网络流)
- poj 3281 Dining Maxflow
- POJ 3281 Dining
- poj 3281 Dining //SAP
- POJ 3281 Dining
- poj 3281 Dining
- poj 3281 Dining
- POJ 3281 Dining
- POJ 3281 Dining
- poj 3281 Dining
- POJ-3281-Dining
- poj(3281)Dining
- POJ 3281 Dining
- poj 3281 Dining
- poj 3281 Dining
- POJ 3281 Dining
- POJ 3281 Dining
- 函数调用约定
- JAVA内存模型和线程安全
- 讯为Exynos4412开发板例程及注释——LED
- 【20170929】python_语言设计(1)基本语法
- 关于矩阵存在共线性的第二谈
- PKU 3281 Dining
- 指针和引用详细比较
- 调用浏览器的打印预览
- tk1 刷机血路
- java程序员笔试试题
- 使用Burp Suite做http proxy抓取android请求
- Dubbo client 启动报错:No provider available for the service use dubbo version 2.5.3
- android开发-自定义控件顺序
- 讯为Exynos4412开发板例程及注释——驱动模块传递参数