294人阅读 评论(0)

# 奔小康赚大钱

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7423    Accepted Submission(s): 3301

Problem Description

Input

Output

Sample Input
2
100 10
15 23

Sample Output
123

Source

Recommend
lcy   |   We have carefully selected several similar problems for you:  2063 1068 3360 1083 2444

const int maxn = 310;
const int INF = 0x3f3f3f3f;

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<malloc.h>
using namespace std;
typedef long long ll;
const int maxn = 310;
const int INF = 0x3f3f3f3f;
int nx,ny;//两边的点数
int g[maxn][maxn];//二分图描述
int slack[maxn];
bool visx[maxn],visy[maxn];
bool DFS(int x)
{
visx[x] = true;
for(int y = 1; y <= ny; y++)
{
if(visy[y])continue;
int tmp = lx[x] + ly[y] - g[x][y];
if(tmp == 0)
{
visy[y] = true;
{
return true;
}
}
else if(slack[y] > tmp)
slack[y] = tmp;
}
return false;
}
int KM()
{
memset(lx,0,sizeof(lx));
memset(ly,0,sizeof(ly));
for(int i = 1; i <= nx; i++)
{
lx[i] = -INF;
for(int j = 1; j <= ny; j++)
if(g[i][j] > lx[i])
lx[i] = g[i][j];
}
for(int x = 1; x <= nx; x++)
{
for(int i = 1; i <= ny; i++)
slack[i] = INF;
while(true)
{
memset(visx,false,sizeof(visx));
memset(visy,false,sizeof(visy));
if(DFS(x))break;
int d = INF;
for(int i = 1; i <= ny; i++)
if(!visy[i] && d > slack[i])
d = slack[i];
for(int i = 1; i <= nx; i++)
if(visx[i])
lx[i] -= d;
for(int i = 1; i <= ny; i++)
{
if(visy[i])ly[i] += d;
else slack[i] -= d;
}
}
}
int res = 0;
for(int i = 1; i <= nx; i++)
return res;
}
int main()
{
int n;
while(scanf("%d",&n) == 1)
{
for(int i = 1; i <= n; i++)
for(int j =1; j <= n; j++)
scanf("%d",&g[i][j]);
nx = ny = n;
printf("%d\n",KM());
}
return 0;
}
/**
2
100 10
15 23
**/


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：421498次
• 积分：13537
• 等级：
• 排名：第985名
• 原创：906篇
• 转载：20篇
• 译文：0篇
• 评论：427条
我的联系方式
友情链接