跟上题(文理分科)几乎一样啊。

结果findflow没有h[x]==0 T了N次。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
const int inf=999999999;int n,m;struct node
{int x,y,c,next,other;
}a[5100000];int len,last[2100000];
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 st,ed,h[2100000],list[2100000];
bool bt_h()
{memset(h,0,sizeof(h));h[st]=1;int head=1,tail=2;list[1]=st;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;tail++;}}head++;}if(h[ed]==0)return false;return true;
}
int findflow(int x,int f)
{if(x==ed)return f;int s=0;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){int 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;
}//-----------wang luo liu-------------int sum;
int point(int x,int y){return (x-1)*m+y;}
void compostion()
{st=n*m+1,ed=n*m+2;int x;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&x), ins(st,point(i,j),x), sum+=x;for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)scanf("%d",&x), ins(point(i,j),ed,x), sum+=x;int cnt=ed;for(int i=1;i<n;i++)for(int j=1;j<=m;j++){scanf("%d",&x);cnt++;ins(st,cnt,x);ins(cnt,point(i,j),inf);ins(cnt,point(i+1,j),inf);sum+=x;}for(int i=1;i<n;i++)for(int j=1;j<=m;j++){scanf("%d",&x);cnt++;ins(cnt,ed,x);ins(point(i,j),cnt,inf);ins(point(i+1,j),cnt,inf);sum+=x;}for(int i=1;i<=n;i++)for(int j=1;j<m;j++){scanf("%d",&x);cnt++;ins(st,cnt,x);ins(cnt,point(i,j),inf);ins(cnt,point(i,j+1),inf);sum+=x;}for(int i=1;i<=n;i++)for(int j=1;j<m;j++){scanf("%d",&x);cnt++;ins(cnt,ed,x);ins(point(i,j),cnt,inf);ins(point(i,j+1),cnt,inf);sum+=x;}
}int main()
{scanf("%d%d",&n,&m);sum=0;compostion();int ans=0;while(bt_h()==true){ans+=findflow(st,inf);}printf("%d\n",sum-ans);return 0;
}

转载于:https://www.cnblogs.com/AKCqhzdy/p/8426882.html

bzoj2127: happiness相关推荐

  1. [bzoj2127]happiness

    来自FallDream的博客,未经允许,请勿转载,谢谢. 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科与 ...

  2. bzoj2127 happiness 最小割

    不要往费用流上想,要往最小割上想,舍弃的权值最小,然后就想一下放到哪边有哪些贡献,不同位置会割掉不同贡献的边, 然后枚举各种割的情况,赋边权就可以了 码: #include<iostream&g ...

  3. 【BZOJ2127】happiness(网络流dinic)

    题目描述 传送门 题解 最小割,割掉的是舍弃的喜悦值. 从s向每一个人连边,容量为这个人学文的喜悦值:从每个人向t连边,容量为这个人学理的喜悦值. 处理两个人共同学文或学理的喜悦值的话,可以每两个人增 ...

  4. The greatest happiness 2019-11-13

    One of the greatest happiness of a person is to devote himself to a career that he is interested in. ...

  5. 基于bert模型的文本分类研究:“Predict the Happiness”挑战

    1. 前言 在2018年10月,Google发布了新的语言表示模型BERT-"Bidirectional Encoder Representations from Transformers& ...

  6. 1463. Happiness to People!

    http://acm.timus.ru/problem.aspx?space=1&num=1463 树形DP 此题有个陷阱   就是图的本身是一个森林 不是树 由于所有 happiness 的 ...

  7. BZOJ 2127: happiness

    2127: happiness Time Limit: 51 Sec  Memory Limit: 259 MB Submit: 2084  Solved: 1028 Description 高一一班 ...

  8. happiness[国家集训队2011(吴确)]

    [试题来源] 2011中国国家集训队命题答辩 [问题描述] 高一一班的座位表是个n*m的矩阵,经过一个学期的相处,每个同学和前后左右相邻的同学互相成为了好朋友.这学期要分文理科了,每个同学对于选择文科 ...

  9. 夯实基础项目工程之图论——Uncle Bogdan and Country Happiness,Graph Coloring,How Many Paths?,Array Differentiation

    文章目录 做题情况项目报告 Uncle Bogdan and Country Happiness Graph Coloring How Many Paths? Array Differentiatio ...

最新文章

  1. 电气专业的你,2022届求职进展如何?
  2. python下载大文件-golang/python 下载大文件时怎样避免oom
  3. 大数运算(7)——大数阶乘(求阶乘)
  4. 欧式距离、曼哈顿距离、余弦相似度(python代码)
  5. 消息队列一直建立tcp连接_云架构那些事儿:为什么我的TCP连接建立异常?
  6. 纪事:最后的足球比赛
  7. js数组获取index_通过事例重温一下常见的 JS 中 15 种数组操作(备忘清单)
  8. FastDFS服务器搭建
  9. 终于来了!Pyston v2.0 发布,速度比 Python 快 20%!
  10. 安装RabbitMq启动运行出现服务无法启动 发生系统错误1067解决方案
  11. 【Essay】开始研究生小论文的撰写
  12. windows 搭建kms服务器激活_自建KMS激活服务器的技巧
  13. 小猪短租陈驰:共享经济不是简单的资本游戏
  14. idea 中部署 tomcat
  15. 新年贺卡php,PS设计2016猴年大吉新年贺卡
  16. 企业债和公司债的四点区别
  17. FCOS搭建环境bug
  18. 多点移动电子地图定位
  19. 微信小程序开发之——拍照上传
  20. Linux——shell脚本

热门文章

  1. BZOJ1010 [HNOI2008]玩具装箱
  2. E/Trace: error opening trace file: No such file or directory
  3. VS调试时断点无法进入或命中的原因及解决方法(PDB引发的)
  4. document.documentElement和document.body的区别
  5. windows常见端口和协议--SMB(445)-NETBIOS(137-138-139)
  6. Spark源码分析之Master启动和通信机制
  7. (213)initial是否可综合?
  8. html如何实现字体逐个输入,HTML – 如何将字体真棒图标插入文本输入?
  9. 前端 domparser未定义怎么解决_统一异常处理到底应该怎么做呢?
  10. efcore 批量_EFcore使用EFCore.BulkExtensions 批量增加、删除、修改