【UVA - 11383】Claw Golden Tiger (二分图最优匹配,KM算法原理)

题干:

   粘贴不过来。。。

题目大意:

    500*500带权格子,每行每列要确定一个值,使row[i]+col[j] >= val[i][j],要使所有row值和col值的和最小

输出每行的row[i],和每列的col[i]。

解题报告:

    跑一边KM,自带着就把我们需要的期望值给求出来了。

AC代码:

#include <iostream>
#include <cstring>
#include <cstdio>using namespace std;
const int MAXN = 505;
const int INF = 0x3f3f3f3f;
int line[MAXN][MAXN];
int ex[MAXN],ey[MAXN];
bool visx[MAXN];
bool visy[MAXN];
int nxt[MAXN];
int slack[MAXN];
int N;
bool dfs(int x) {visx[x] = 1;for (int y = 1; y <= N; ++y) {if (visy[y]) continue; int tmp = ex[x] + ey[y] - line[x][y];if (tmp == 0) {visy[y] = 1;if (nxt[y] == -1 || dfs( nxt[y] )) {nxt[y] = x;return 1;}} else if(slack[y] > tmp) slack[y] = tmp;}return 0;
}
int KM() {memset(nxt, -1, sizeof nxt);memset(ey, 0, sizeof ey);for (int i = 1; i <= N; ++i) {ex[i] = line[i][1];for (int j = 2; j <= N; ++j) {ex[i] = max(ex[i], line[i][j]);}}for (int i = 1; i <= N; ++i) {fill(slack, slack + N + 1, INF);while (1) {memset(visx, 0, sizeof visx);memset(visy, 0, sizeof visy);if (dfs(i)) break;int d = INF;for (int j = 1; j <= N; ++j)if (!visy[j]) d = min(d, slack[j]);for (int j = 1; j <= N; ++j) {if (visx[j]) ex[j] -= d;if (visy[j]) ey[j] += d;else slack[j] -= d;}}}int res = 0;for (int i = 1; i <= N; ++i) res += line[ nxt[i] ][i];return res;
}
int main() {while (~scanf("%d",&N)) {for (int i = 1; i <= N; ++i)for (int j = 1; j <= N; ++j)scanf("%d", &line[i][j]);int ans = KM();for(int i = 1; i<=N; i++) {printf("%d%c",ex[i],i == N ? '\n' : ' ');}for(int i = 1; i<=N; i++) {printf("%d%c",ey[i],i == N ? '\n' : ' ');}printf("%d\n",ans);}return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441431.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

git object 很大_这才是真正的Git——Git内部原理

本文以一个具体例子结合动图介绍了Git的内部原理&#xff0c;包括Git是什么储存我们的代码和变更历史的、更改一个文件时&#xff0c;Git内部是怎么变化的、Git这样实现的好处等等。TL;DR本文以一个具体例子结合动图介绍了Git的内部原理&#xff0c;包括Git是什么储存我们的代码…

【CodeForces - 195D】Analyzing Polyline (思维,卡精度的处理方式)

题干&#xff1a; As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son …

【CodeForces - 985D】Sand Fortress (二分,贪心,思维构造,技巧,有坑)

题干&#xff1a; You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbe…

mysql多实例脚本_mysql多实例脚本

mysql多实例脚本##mariadb和mysql-server的通用多实例脚本。vi mdp.sh 脚本内容参考内容如下#!/bin/bashecho ‘等待mariadb-server或mysql-server服务软件安装完毕’while truedoyum install -y mariadb-server mariadb &>/dev/nullyum install -y mysql-serv…

scrapy 分布式 mysql_Scrapy基于scrapy_redis实现分布式爬虫部署的示例

准备工作1.安装scrapy_redis包,打开cmd工具,执行命令pip install scrapy_redis2.准备好一个没有BUG,没有报错的爬虫项目3.准备好redis主服务器还有跟程序相关的mysql数据库前提mysql数据库要打开允许远程连接,因为mysql安装后root用户默认只允许本地连接,详情请看此文章部署过程…

(精)DEVC++的几个实用小技巧

依赖 DEV C 5.11 最新版 下载安装DEV C后&#xff0c;使用DEV C打开一个随便的cpp文件&#xff0c;你看到的应该是这样的界面。&#xff08;为了节约读者的流量&#xff0c;图片进行了有损压缩&#xff0c;但是字看得清楚&#xff09; 重点是确认工具栏有AStyle选项。 相信…

win10一按右键就闪屏_升级Win10正式版后屏幕一直闪烁正确的解决办法

Win10正式版屏幕一直闪烁怎么办呢&#xff1f;升级到Win10正式版并进入Windows桌面后&#xff0c;发现屏幕一直不断的闪烁&#xff0c;此时无法执行任务操作。小编最近在升级到Win10正式版后才遇到了这个问题&#xff0c;后台经过反复思考和探索&#xff0c;终于解决了问题&…

KMP 常用模板

写在前面&#xff1a; 代码中有的是i&#xff0c;j&#xff0c;有的是j&#xff0c;k&#xff0c;总之不唯一啊&#xff01;&#xff01;&#xff01;这个一定要弄清楚&#xff01;&#xff01;&#xff01;我没有统一。。 从0开始的字符串&#xff0c;加速版。 void getnext…

在spark的软件栈中_问:Spark Streaming是什么软件栈中的流计算?

问&#xff1a;Spark Streaming是什么软件栈中的流计算?A:不能确定,B:,C:,D:正确答案:绛旓細姣斿皵路鐩栬尐解析&#xff1a;问&#xff1a;Spark Streaming是什么软件栈中的流计算?A:不能确定,B:,C:,D:相关问题&#xff1a;“逻辑与”的运算符是( )。A:&&B:&C:…

【CodeForces - 195A】Let's Watch Football (追及问题,模拟)

题干&#xff1a; Valeric and Valerko missed the last Euro football game, so they decided to watch the games key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, i…

下面不是mysql特性_下面( )不是MySQL的特性。_学小易找答案

【单选题】如何检测 2型糖尿病【填空题】<5>以下do-while语句中循环体的执行次数是( ). a10; b0; do { b2; a-2b; } while (a>0);【单选题】2 型糖尿病 多 发在什么年龄段【填空题】<5>以下程序的输出结果为( )。 #include "stdio.h" main() {int a; …

*【CodeForces - 195B】After Training (多解,模拟)

题干&#xff1a; After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has n balls and m baskets. The baskets are positioned in a row from l…

pandas打印全部列_python——pandas练习题1-5

练习1-开始了解你的数据探索Chipotle快餐数据相应数据集&#xff1a;chipotle.tsvimport pandas as pd chipopd.read_csv("exercise_data/chipotle.tsv",sept) chipo.head(5)chipo.shape[0] #查看有多少行4622chipo.shape[1] #查看有多少列5chipo.columns #打印所…

【POJ - 2406】Power Strings (KMP,最小循环节)

题干&#xff1a; Given two strings a and b we define a*b to be their concatenation. For example, if a "abc" and b "def" then a*b "abcdef". If we think of concatenation as multiplication, exponentiation by a non-negative in…

python wmi mac变动_Python WMI参数反转

使用python的wmi模块创建vss快照&#xff0c;我发现除非将它们反向&#xff0c;否则这些参数将不起作用&#xff1a;importwmidefvss_create():shadow_copy_servicewmi.WMI(monikerwinmgmts:\\\\.\\root\\cimv2:Win32_ShadowCopy)resshadow_copy_service.Create(ClientAccessib…

【 HDU - 2594 】Simpsons’ Hidden Talents(KMP应用,求最长前缀后缀公共子串)

题干&#xff1a; Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marge: Yeah, what is it? Homer: Take me for example. I want to find out if I have a talent in politics, OK? Marge: OK. Homer: So I take…

python两次调用write连续写入的数据之间_两次调用文件的write 方法,以下选项中描述正确的是...

两次调用文件的write 方法&#xff0c;以下选项中描述正确的是答&#xff1a;连续写入的数据之间无分隔符中国大学MOOC: 斜弯曲、拉(压)弯曲组合变形的危险点都是单向应力状态。答&#xff1a;对急性宫外孕破裂或的最主要症状是答&#xff1a;突然一侧下腹部撕裂样疼痛Some thi…

拉格朗日差值 - 杜教板子

牛客网暑期ACM多校训练营(第一场) F Sum of Maximum 杜教板子&#xff1a; 证明https://blog.csdn.net/Lee_w_j__/article/details/81135539 #include <cstdio> #include <iostream> #include <vector> #include <cstring> #include <algorithm&…

python归并排序 分词_python实现归并排序,归并排序的详细分析

学习归并排序的过程是十分痛苦的。它并不常用&#xff0c;看起来时间复杂度好像是几种排序中最低的&#xff0c;比快排的时间复杂度还要低&#xff0c;但是它的执行速度不是最快的。很多朋友不理解时间复杂度低为什么运行速度不一定快&#xff0c;这个不清楚的伙伴可以看下我之…

CCFCSP 2018年9月 -- 部分题目

CCF201809 -- 第一题 &#xff1a;买菜 问题描述   在一条街上有n个卖菜的商店&#xff0c;按1至n的顺序排成一排&#xff0c;这些商店都卖一种蔬菜。   第一天&#xff0c;每个商店都自己定了一个正整数的价格。店主们希望自己的菜价和其他商店的一致&#xff0c;第二天…