题目

题目传送门:https://www.luogu.com.cn/problem/UVA11383

分析

最近刚刚学了二分图,然后来了一个这样的题,看完题意之后,稍微想一想就能想出来是一个二分图,然后就是裸的板子解决。没什么难的。

代码

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#define ll long long
using namespace std;
const int maxn=1e3+;
const int Inf=0x3f3f3f3f;
ll n,mi;
ll x[maxn],y[maxn],w[maxn][maxn],mat[maxn];
bool S[maxn],T[maxn];
bool Match(ll u){
S[u]=true;
for(ll i=;i<=n;++i){
if(!T[i]){
ll tmp(x[u]+y[i]-w[u][i]);
if(!tmp){
T[i]=true;
if(!mat[i] || Match(mat[i])){
mat[i]=u;
return true;
}
}
else
mi=min(mi,tmp);
}
}return false;
}
void Update(){
for(ll i=;i<=n;++i)
if(S[i]) x[i]-=mi;
for(ll i=;i<=n;++i)
if(T[i]) y[i]+=mi;
}
void KM(){
for(ll i=;i<=n;++i){
mat[i]=x[i]=y[i]=;
for(ll j=;j<=n;++j)
x[i]=max(x[i],w[i][j]);
}
for(ll i=;i<=n;++i){
while(true){
for(ll i=;i<=n;++i)
S[i]=T[i]=false;
mi=Inf;
if(Match(i)) break;
else Update();
}
}
}
int main(){
while(scanf("%d",&n)!=EOF&&n){
for(ll i=;i<=n;++i)
for(ll j=;j<=n;++j)
scanf("%d",&w[i][j]);
KM();
ll ans=;
for(ll i=;i<=n;++i)
ans+=x[i];
for(ll i=;i<=n;++i)
ans+=y[i]; printf("%d",x[]);
for(ll i=;i<=n;++i)
printf(" %d",x[i]);printf("\n");
printf("%d",y[]);
for(ll i=;i<=n;++i)
printf(" %d ",y[i]);printf("\n"); printf("%d\n",ans);
}return ;
}

最新文章

  1. Windows Azure Storage (20) 使用Azure File实现共享文件夹
  2. T-SQL中的随机数
  3. Endless Sky源码学习笔记-3
  4. 技术英文单词贴--R
  5. echo和print语句
  6. css 权威指南笔记(四)选择器
  7. formidable上传图片
  8. android变化HOLO对话风格
  9. 面试题-Java Web-网络通信
  10. BestCoder Round #86 A B C
  11. HTML+JS+JQuery不可以使用status
  12. 获得最近一天的提交,并使用winscp上传到服务器
  13. tomcat配置问题:访问http://localhost:8080/ 遇到 Access Error: 404
  14. Spring MVC+Mybatis 多数据源配置
  15. 第10课 C++中的新成员
  16. PHP使用FPDF pdf添加水印中文乱码问题 pdf合并版本问题
  17. &lt;s:action&gt;的一些用法
  18. nc命令的常用参数介绍
  19. LTE:EPC
  20. jquery colsest的用法

热门文章

  1. Java实现 LeetCode 732 我的日程安排表 III(暴力 || 二叉树)
  2. (Java实现) 有重复元素排列问题
  3. Java实现 LeetCode 449 序列化和反序列化二叉搜索树
  4. Android中WebView如何加载JavaScript脚本
  5. Java实现台阶问题
  6. Java实现完美洗牌算法
  7. http1.0 、http1.1和http2.0的区别
  8. 批量执行app自动化测试思路设计图
  9. 使用Volo.Abp.MailKit发送邮件
  10. 记一次@ResponseBody注解返回中文乱码的问题