bzoj2127: happiness(最小割)
題目傳送門
。。
解法:
跟文理分科有什麼區別。
詳情請見此blog
程式碼實現:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
struct node {int x,y,c,next,other;}a[1100000];int len,last[51000];
void ins(int x,int y,int c) {
int k1,k2;
len++;k1=len;a[len].x=x;a[len].y=y;a[len].c=c;a[len].next=last[x];last[x]=len;
len++;k2=len;a[len].x=y;a[len].y=x;a[len].c=0;a[len].next=last[y];last[y]=len;
a[k1].other=k2;a[k2].other=k1;
}
int list[51000],head,tail,h[51000],st,ed;
bool bt_h() {
list[1]=st;head=1;tail=2;memset(h,0,sizeof(h));h[st]=1;
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]==0&&a[k].c>0) {h[y]=h[x]+1;list[tail++]=y;}
}head++;
}if(h[ed]==0)return false;return true;
}
int findflow(int x,int f) {
if(x==ed)return f;
int s=0,t;
for(int k=last[x];k;k=a[k].next) {
int y=a[k].y;
if(h[y]==h[x]+1&&a[k].c>0&&s<f) {t=findflow(y,min(a[k].c,f-s));s+=t;a[k].c-=t;a[a[k].other].c+=t;}
}if(s==0)h[x]=0;return s;
}
int n,m,map[110][110];const int inf=999999999;
int pt(int x,int y) {return (x-1)*m+y;}
int main() {
//freopen("happiness.in","r",stdin);freopen("happiness.out","w",stdout);
scanf("%d%d",&n,&m);st=n*m*5+1;ed=st+1;int sum=0;len=0;memset(last,0,sizeof(last));
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) {int x;scanf("%d",&x);sum+=x;ins(st,pt(i,j),x);}
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) {int x;scanf("%d",&x);sum+=x;ins(pt(i,j),ed,x);}
for(int i=1;i<n;i++)for(int j=1;j<=m;j++) {
int x;scanf("%d",&x);sum+=x;ins(st,pt(i,j)+n*m,x);ins(pt(i,j)+n*m,pt(i+1,j),inf);ins(pt(i,j)+n*m,pt(i,j),inf);
}
for(int i=1;i<n;i++)for(int j=1;j<=m;j++) {
int x;scanf("%d",&x);sum+=x;ins(pt(i,j)+n*m*2,ed,x);ins(pt(i+1,j),pt(i,j)+n*m*2,inf);ins(pt(i,j),pt(i,j)+n*m*2,inf);
}
for(int i=1;i<=n;i++)for(int j=1;j<m;j++) {
int x;scanf("%d",&x);sum+=x;ins(st,pt(i,j)+n*m*3,x);ins(pt(i,j)+n*m*3,pt(i,j+1),inf);ins(pt(i,j)+n*m*3,pt(i,j),inf);
}
for(int i=1;i<=n;i++)for(int j=1;j<m;j++) {
int x;scanf("%d",&x);sum+=x;ins(pt(i,j)+n*m*4,ed,x);ins(pt(i,j+1),pt(i,j)+n*m*4,inf);ins(pt(i,j),pt(i,j)+n*m*4,inf);
}int ans=0;while(bt_h()==true)ans+=findflow(st,inf);printf("%d\n",sum-ans);
return 0;
}
相關文章
- 最大流最小割
- 網路流-最小割
- bzoj4808: 馬(最小割)
- bzoj3275: Number(最小割)
- 網路流(最大流,最小割)
- 偷寶石(最大流轉化最小割)
- bzoj1391: [Ceoi2008]order(最小割)
- 1.1.3.3 最小割之最小權覆蓋集、最大權獨立集
- The Way to HappinessAPP
- SPOJ - OPTM Optimal Marks(進位制拆分+最小割)
- 網路流最大流、最小割學習筆記筆記
- bzoj3175: [Tjoi2013]攻擊裝置(最小割)
- 【BZOJ-1565】植物大戰殭屍 拓撲排序 + 最小割排序
- 論文導讀 | 最小屬性割RDF資料劃分
- UVA 10498 Happiness!(線性規劃)APP
- [LeetCode] 3075. Maximize Happiness of Selected ChildrenLeetCodeAPP
- P2057 [SHOI2007]善意的投票 / [JLOI2010]冠軍調查( 最小割 )
- P3388 【模板】割點(割頂)
- 無向圖最小割問題取得新突破,谷歌研究獲SODA 2024最佳論文獎谷歌
- Codeforces 1974G Money Buys Less Happiness NowAPP
- 洛谷 P3388 【模板】割點(割頂)
- Day7 割點、割邊和強連通分量
- 嗅探器(割點)
- Codeforces Round 946 (Div. 3) G Money Buys Less Happiness Now(反悔貪心)APP
- 【筆記/模板】割點和橋筆記
- 最小堆
- 一次被割韭菜的覆盤
- oracle重要系統割接準備工作Oracle
- Nginx - 最小配置Nginx
- win10分割槽好了怎麼刪除_win10分割槽完後如何刪除Win10
- 無向連通圖求割點和橋
- LeetCode-最小棧LeetCode
- 155. 最小棧
- 155.最小棧
- (樹_)求最小深度
- 建立最小的SpringBootSpring Boot
- 最小生成樹
- 最小圓覆蓋
- 為什麼你總是覺得被割韭菜?