# 奔小康赚大钱

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
**/


• 本文已收录于以下专栏：

举报原因： 您举报文章：HDU 2255-奔小康赚大钱（Kuhn-Munkras算法/KM算法-完备匹配下的最大权匹配） 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)