BNUOJ 1268 PIGS
PIGS
This problem will be judged on PKU. Original ID: 1149
64-bit integer IO format: %lld Java class name: Main
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 arives, 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 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
Sample Input
3 3
3 1 10
2 1 2 2
2 1 3 3
1 2 6
Sample Output
7
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <queue>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int n,m,a[maxn],p[maxn];
int arc[maxn][maxn],pre[maxn],pigs[maxn];
int bfs(){
int u,v,f = ;
queue<int>q;
while(true){
while(!q.empty()) q.pop();
memset(a,,sizeof(a));
memset(p,,sizeof(p));
a[] = INF;
q.push();
while(!q.empty()){
u = q.front();
q.pop();
for(v = ; v <= n+; v++){
if(!a[v] && arc[u][v] > ){
a[v] = min(a[u],arc[u][v]);
p[v] = u;
q.push(v);
}
}
if(a[n+]) break;
}
if(!a[n+]) break;
for(u = n+; u; u = p[u]){
arc[p[u]][u] -= a[n+];
arc[u][p[u]] += a[n+];
}
f += a[n+];
}
return f;
}
int main(){
int i,j,k,buy,e;
while(~scanf("%d%d",&m,&n)){
memset(arc,,sizeof(arc));
memset(pre,,sizeof(pre));
for(i = ; i <= m; i++)
scanf("%d",pigs+i);
for(i = ; i <= n; i++){
scanf("%d",&k);
while(k--){
scanf("%d",&e);
if(pre[e]) arc[pre[e]][i] = INF;
else arc[pre[e]][i] += pigs[e];
pre[e] = i;
}
scanf("%d",&buy);
arc[i][n+] += buy;
}
cout<<bfs()<<endl;
}
return ;
}
BNUOJ 1268 PIGS的更多相关文章
- POJ1149 PIGS [最大流 建图]
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20662 Accepted: 9435 Description ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- POJ 1149 PIGS
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20579 Accepted: 9387 Description ...
- Leetcode: Poor Pigs
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. Th ...
- BNUOJ 52325 Increasing or Decreasing 数位dp
传送门:BNUOJ 52325 Increasing or Decreasing题意:求[l,r]非递增和非递减序列的个数思路:数位dp,dp[pos][pre][status] pos:处理到第几位 ...
- bnuoj 24251 Counting Pair
一道简单的规律题,画出二维表将数字分别相加可以发现很明显的对称性 题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=24251 #include< ...
- ural 1268. Little Chu
1268. Little Chu Time limit: 0.25 secondMemory limit: 64 MB The favorite occupation of Little Chu is ...
- bnuoj 44359 快来买肉松饼
http://www.bnuoj.com/contest/problem_show.php?pid=44359 快来买肉松饼 Time Limit: 5000 ms Case Time Lim ...
- PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...
随机推荐
- Coins HDU - 2844 POJ - 1742
Coins HDU - 2844 POJ - 1742 多重背包可行性 当做一般多重背包,二进制优化 #include<cstdio> #include<cstring> in ...
- 2018年全国多校算法寒假训练营练习比赛(第五场):A题:逆序数(树状数组or归并排序)
题目描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.比如一个序列为4 5 1 3 2, 那么这个序列 ...
- 1268 和为K的组合 Meet in mid二分思路
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1268&judgeId=193772 给出n = 20个数,问其是 ...
- HBase Region Assign流程详解
Hbase是kv存储,但是逻辑上我们可以把存储在hbase上的kv数据当成表,rowkey可以认为是表的主键.为了便于分布式操作,hbase会把表横向切分成一块一块的数据,而每块就是一个Region. ...
- AJPFX总结final、finally、finallize的区别
final.finally.finallize有何区别? final表示一个修饰符,如果用它来修饰一个类,则该类是不能继承的:如果用它来修饰一个变量,则该变量一旦赋值之后就不能再修改:如果用它来 ...
- 微软2017年预科生计划在线编程笔试 A Legendary Items
思路: 获得第i(i = 0, 1, ..., n - 1)件物品的概率仅由公式p / (1 << i)决定,所以获得这i件物品之间是相互独立的.迭代计算获得所有i件物品的期望再求和即可. ...
- vue项目中安装cnpm和node_modules
1.安装cnpm的nodejs包管理工具,命令行: npm install -g cnpm --registry=https://registry.npm.taobao.org 2. 每个vue项 ...
- vue全局loading组件
本组件作用在页面加载完成前进行loader提示,提升用户体验,只需要在app.vue中引用一次,整个项目中路由切换时就可以自动进行提示(vuex版): 1. 添加vuex值和方法: import Vu ...
- git---安装及配置
git官网:https://git-scm.com 安装: 官网下载->一路Next->安装完成 配置git: 1.win+r进入windows命令行 2.注册: git config - ...
- 掌握Spark机器学习库-07-回归分析概述
1)回归与分类算法的区别 回归的预测结果是连续的,分类的预测结果是离散的. 2)spark实现的回归算法有: 3)通过相关系数衡量线性关系的程度