点击打开链接

PIGS
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14204   Accepted: 6305

Description

Mirko works on a pig farm that consists of M locked pig-houses and Mirko can't unlock any pighouse because he doesn't have the keys. Customers come to the farm one after another. Each of them has keys to some pig-houses and wants to buy a certain number of pigs.
All data concerning customers planning to visit the farm on that particular day are available to Mirko early in the morning so that he can make a sales-plan in order to maximize the number of pigs sold.
More precisely, the procedure is as following: the customer arrives, opens all pig-houses to which he has the key, Mirko sells a certain number of pigs from all the unlocked pig-houses to him, and, if Mirko wants, he can redistribute the remaining pigs across the unlocked pig-houses.
An unlimited number of pigs can be placed in every pig-house.
Write a program that will find the maximum number of pigs that he can sell on that day.

Input

The first line of input  contains two integers M and N, 1 <= M <= 1000, 1 <= N <= 100, number of pighouses and number of customers. Pig houses are numbered from 1 to M and customers are numbered from 1 to N.
The next line contains M integeres, for each pig-house initial number of pigs. The number of pigs in each pig-house is greater or equal to 0 and less or equal to 1000.
The next N lines contains records about the customers in the following form ( record about the i-th customer is written in the (i+2)-th line):
A K1 K2 ... KA B It means that this customer has key to the pig-houses marked with the numbers K1, K2, ..., KA (sorted nondecreasingly ) and that he wants to buy B pigs. Numbers A and B can be equal to 0.

Output

The first and only line of the output should contain the number of sold pigs.

Sample Input

3 3
3 1 10
2 1 2 2
2 1 3 3
1 2 6

Sample Output

7

Source

Croatia OI 2002 Final Exam - First day

题意:有M个猪圈,每个猪圈里初始时有若干头猪。一开始所有猪圈都是关闭的。依次来了N个顾客,每个顾客分别会打开指定的几个猪圈,从中买若干头猪。每个顾客分别都有他能够买的数量的上限。每个顾客走后,他打开的那些猪圈中的猪,都可以被任意地调换到其它开着的猪圈里,然后所有猪圈重新关上。问总共最多能卖出多少头猪。(1 <= N <= 100, 1 <= M <= 1000)。

建图:

每个顾客分别用一个结点来表示。
对于每个猪圈的第一个顾客,从源点向他连一条边,容量就是该猪圈里的猪的初始数量。如果从源点到一名顾客有多条边,则可以把它们合并成一条,容量相加。
 对于每个猪圈,假设有n个顾客打开过它,则对所有整数i∈[1, n),从该猪圈的第i个顾客向第i + 1个顾客连一条边,容量为∞。
 从各个顾客到汇点各有一条边,容量是各个顾客能买的数量上限。

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
#define INF 9999999
int n,m;
int map[300][300],pre[300],flow[300][300],p[300],a[300];
int EK(int s,int t)
{int sum=0;queue<int>q;memset(flow,0,sizeof(flow));for(;;){memset(a,0,sizeof(a));//记录残量a[s]=INF;q.push(s);while(!q.empty()){int u=q.front();q.pop();for(int i=1; i<=t; i++)if(!a[i]&&map[u][i]>flow[u][i]){p[i]=u;//记录i的父亲节的是uq.push(i);a[i]=a[u]<map[u][i]-flow[u][i]?a[u]:map[u][i]-flow[u][i];}}if(!a[t])break;//如果残量是0的话,就找到最大流for(int i=t; i!=s; i=p[i])//每条路加上最小残量{flow[p[i]][i]+=a[t];flow[i][p[i]]-=a[t];}sum+=a[t];//记录流量}return sum;
}
int main()
{int a,b,c,max;int pig[1007],link[1007];while(scanf("%d%d",&n,&m)!=EOF){memset(map,0,sizeof(map));memset(p,0,sizeof(p));memset(link,0,sizeof(link));memset(pig,0,sizeof(pig));int t=m+1;for(int i=1;i<=n;i++)scanf("%d",&pig[i]);for(int i=1;i<=m;i++){scanf("%d",&a);for(int j=1;j<=a;j++){scanf("%d",&b);if(link[b]==0){link[b]=i;map[0][i]+=pig[b];}else{map[link[b]][i]=INF;}}scanf("%d",&map[i][t]);}max=EK(0,t);printf("%d\n",max);}return 0;
}

POJ 1149 PIGS 最大流建模相关推荐

  1. poj 1149 PIGS【最大流】

    建图:s向所有猪圈的第一个顾客连流量为这个猪圈里住的数量,然后对于之后每个来这个猪圈的顾客,由他前一个顾客向他连边权为无穷的边,然后每个顾客向t连流量为这个顾客购买上限的边.然后跑最大流 #inclu ...

  2. POJ 1149(最大流)

    这道题应该都能想到朴素的有n*m+个点的建图方案吧,呵呵,显然是不行的. 那么怎么办? 其实我们可以这样想:一个人能买到的猪有两个来源: ①来自自己第一次打开的猪圈 ②来自之前别人打开的猪圈 想到了这 ...

  3. POJ 1149 PIGS

    POJ_1149 这个题目搞得我比较纠结,具体的思想还是看看这篇博客吧. http://imlazy.ycool.com/post.2059102.html #include<stdio.h&g ...

  4. 为多孔介质的当量直径_多孔介质流建模简介

    拥有一款先进的多孔介质建模工具,是许多行业的刚性需求.COMSOL Multiphysics® 软件 5.5 版本新增的附加产品--多孔介质流模块,可以满足众多行业的需求.使用该模块可以定量研究多孔介 ...

  5. POJ.3281 dining 最大流+拆点

    POJ.3281 dining 最大流+拆点 思路清晰为啥一直WA呢 #include <iostream> #include <cstring> #include <v ...

  6. 基于上下文的业务流建模法(二)

    一.背景 上一篇文章说到了我提出了一种新的建模方法,并对建模方法的大概内容做了阐述,本次我将继续对这个建模方法做进一步的说明,并提供一个小小的案例来熟悉一下建模套路.下一篇文章将通过其他案例来展示这种 ...

  7. 基于上下文的业务流建模法(三)

    一.背景 前面两篇文章已经给大家展示了一个相对新颖的建模方法,也简单实战了下,这里我通过一个生活中的例子来模拟快递业务中的模型构建过程,本篇将完整的展示一下基于上下文的业务流建模法的操作过程. 事情的 ...

  8. POJ 1149 最大流建图 PIGS

    题意: 给出猪圈个数 m 和买家人数 n 然后给出m个猪圈的猪的头数.. 接下来 n 行.. 给出mm a1 a2 .. a(mm) k 例如 2 1 5 3 表示第i+1个用户 有mm(2) 个猪圈 ...

  9. Poj(1459),最大流,EK算法

    题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Su ...

最新文章

  1. 百所学校寒假时长排行,看看你的学校排多少名~
  2. “开源”将成为物联网开发生态链的标准
  3. 编译安装LAMP及分离式LAMP平台构建
  4. 第十六届全国大学生智能车竞赛-航天智慧物流创意组-技术培训
  5. 人工智能、大数据、云计算、机器学习和深度学习,主要有什么关系?
  6. Maven的简单配置说明
  7. 分享.NET开发中经常用到的十大软件(转)
  8. 【需求工程】需求应用域理解
  9. linux的安全性能,技术|Linux 系统安全性能检查小记
  10. 自动生成宣传单打印页--提高工作效率
  11. Linux指令设置波特率停止位,linux下的picocom怎么设置停止位,波特率
  12. Linux内核网络协议栈8—socket监听
  13. SDOI2017round1酱油记day0
  14. chrome版本太旧 无法更新 问题解决
  15. 软件工程 超市库存管理系统 可行性研究-需求分析
  16. 大学计算机学术活动,计算机学院学术活动公告---南京理工大学Wai-Tat Fu教授学术报告...
  17. 【高级持续性威胁追踪】SolarWinds供应链攻击持续跟踪进展
  18. 红帽子企业版RHEL5.0 的软件包管理
  19. 机器学习————神经网络
  20. 给自己的网站加入智能聊天功能

热门文章

  1. 31条指令单周期cpu设计(Verilog)-(二)总体设计
  2. Python获取国内股票数据
  3. Python分析万条数据,告诉你奔驰宝马奥迪谁更垃圾!快来学Python!!
  4. HEVC解码学习(1)-HM平台的解码配置
  5. (4) — ARC之循环参照 转自易飞扬
  6. 优秀的图片编辑软件:Posterino for Mac
  7. 打官司证人证言有用吗?
  8. 读Multiscale Vessel Enhancement Filtering笔记
  9. Excel超级表的7个特性,你有必要掌握!
  10. 读书笔记001:托尼.巴赞之开动大脑