bzoj3438: 小M的作物(那年花开最小割)
3438: 小M的作物
题目:传送门
题解:
最小割标准水题(做了几天的最小割之后表示是真的水)
为什么水:博主已经做过两道基本一样的题目了...
详情参考:bzoj3894
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define N 510000
#define inf 999999999
#define qread(x)x=read();
using namespace std;
typedef long long LL;
inline LL read()
{
LL f=,x=;char ch;
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return f*x;
}
struct node
{
int x,y,next,other;
LL c;
}a[N*];int len,last[N];
LL n,m,st,ed,head,tail;
void ins(int x,int y,LL c)
{
int k1,k2;
k1=++len;
a[len].x=x;a[len].y=y;a[len].c=c;
a[len].next=last[x];last[x]=len; k2=++len;
a[len].x=y;a[len].y=x;a[len].c=;
a[len].next=last[y];last[y]=len; a[k1].other=k2;
a[k2].other=k1;
}
int list[N],h[N];
bool bt_h()
{
memset(h,,sizeof(h));h[st]=;
list[]=st;head=;tail=;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]== && a[k].c>)
{
h[y]=h[x]+;
list[tail++]=y;
}
}
head++;
}
if(h[ed]>)return true;
return false;
}
int find_flow(int x,LL flow)
{
if(x==ed)return flow;
LL s=,t;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==h[x]+ && a[k].c> && s<flow)
{
s+=t=find_flow(y,min(a[k].c,flow-s));
a[k].c-=t;a[a[k].other].c+=t;
}
}
if(s==)h[x]=;
return s;
}
LL A[],B[],c1[],c2[];
int main()
{
len=;memset(last,,sizeof(last));
qread(n);
LL sum=;
for(int i=;i<=n;i++){qread(A[i]);sum+=A[i];}
for(int i=;i<=n;i++){qread(B[i]);sum+=B[i];}
qread(m);st=N-;ed=N-;
for(int i=;i<=n;i++)
{
ins(st,i,A[i]);
ins(i,ed,B[i]);
}
for(int i=;i<=m;i++)
{
int k;qread(k);qread(c1[i]);qread(c2[i]);
sum+=c1[i]+c2[i];ins(st,i+n,c1[i]);ins(i+n+m,ed,c2[i]);
for(int j=;j<=k;j++)
{
int x;qread(x);
ins(i+n,x,inf);
ins(x,i+n+m,inf);
}
}
LL ans=;
while(bt_h())ans+=find_flow(st,inf);
printf("%lld\n",sum-ans);
return ;
}
bzoj3438: 小M的作物(那年花开最小割)的更多相关文章
- BZOJ3438 小M的作物(最小割)
题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=3438 Description 小M在MC里开辟了两块巨大的耕地A和B(你可以认为 ...
- BZOJ3438小M的作物——最小割
题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子 有1个(就是可以种一棵作物)(用1...n编号),现在,第i种作物种植在A中种植可 ...
- BZOJ3438 小M的作物
AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3438 这题觉得和上题有点类似吧. 如果没有联合在一起的收成,可以比较好做[我们将属于A的表 ...
- BZOJ3438 小M的作物(和拓展)
题目链接:戳我 我们如果要选择一种种植情况的话,一定是其他的选择都不可行了.这种决策问题用最小割来处理最好不过. 建图方式--A为源点,B为汇点.然后将每个点分别向A,B连边,边权为种植它的价值.组合 ...
- 【bzoj3438】 小M的作物
http://www.lydsy.com/JudgeOnline/problem.php?id=3438 (题目链接) 题意 $n$种作物,每种可以种在A田也可以种在B田,两种种植方法有不同的收益.$ ...
- 【BZOJ3438】小M的作物 最小割
[BZOJ3438]小M的作物 Description 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物的种子,每种作物的种子 有1个(就是可以种一棵作物)(用1. ...
- 【bzoj3438】小M的作物 网络流最小割
原文地址:http://www.cnblogs.com/GXZlegend/p/6801522.html 题目描述 小M在MC里开辟了两块巨大的耕地A和B(你可以认为容量是无穷),现在,小P有n中作物 ...
- 「BZOJ3438」小M的作物(最小割
3438: 小M的作物 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1891 Solved: 801[Submit][Status][Discus ...
- 【BZOJ-3438】小M的作物 最小割 + 最大权闭合图
3438: 小M的作物 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 825 Solved: 368[Submit][Status][Discuss ...
随机推荐
- spring boot pom
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- Servlet体验之旅(二)——Session、Cookie
我们知道Session和Cookie都是用于会话跟踪的,仅仅是实现的方式不大一样,那么他们到底有什么不同呢?以下跟着我脚步来了解一下: Session.Cookie的含义: Session 一种ser ...
- OS 中文斜体 Italic Font Chinese - iOS_Girl
CGAffineTransform matrix = CGAffineTransformMake(1, 0, tanf(15 * (CGFloat)M_PI / 180), 1, 0, 0); UI ...
- poj 2488 A Knight's Journey(dfs+字典序路径输出)
转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----- ...
- bzoj4547: Hdu5171 小奇的集合(矩阵乘法)
4547: Hdu5171 小奇的集合 题目:传送门 题解: 做一波大佬们的坑...ORZ 不得不说,我觉得矩阵很简单啊,就一个3*3的(直接看代码吧) 给个递推柿纸:f[i]=f[i-1]+max1 ...
- 性能监控之监控SQL语句
分析表 analyze table tablename compute statistics for all indexes; analyze table tablename compute stat ...
- Linux下iscsi的使用
查看是否已安装了iscsi-initiator: [root@test\ ~]# rpm -qa |grep iscsi iscsi-initiator-utils-6.2.0.868-0.18.e ...
- Oracle RAC 实施
第 1 步 — 确定项目范围 理由 我们实施 Oracle RAC 是为了使我们的应用程序可伸缩和高度可用,以及为我们的客户提供更可靠的服务. 目标/可交付产品 该项目的最终产品将是一个新的 Orac ...
- Laravel-HTTP-验证
Laravel-HTTP-验证 标签(空格分隔): php 第一种方式 **1 直接在controller里完成表单验证** **2 打印验证返回的错误信息 dd($errors)** 第二种方式 * ...
- JavaScript实现记住密码功能
用js实现记住密码功能,但是前端记住密码不安全,最好还是不要用.我感觉这个记住密码应该是通过与后台建立一个会话来实现. 这个效果的测试地址在:http://ofoyou.com/blog/rePass ...