题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1631
Facility Locations
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 48 Solved: 13
[ Submit][ Status][ Web Board]
Description
The HDWBP Inc. has n clients and needs to service these clients by opening k facilities. Each opened facility can serve any number of clients and each client must be served by an open facility. There are m potential locations for these k facilities. The cost of serving client j at potential location i is a non-negative integer cij . These costs satisfy a locality property: for two clients j and j’ and two facilities i and i’, we have cij ≤ ci’j + ci’j’ + cij’ . Given the costs, the CEO of HDWBP Inc. ultimately wants to know the cheapest way to open k facilities and assign clients to these open facilities. For now, he needs your help to determine if it is possible to do this task without any cost (i.e. with cost zero).
Input
The input consists of a single test case. The first line contains three integers m, n, k where 1 ≤ m ≤ 100, 1 ≤ n ≤ 100 and 1 ≤ k ≤ m. Each of the next m lines contains n non-negative integers where the jth integer in the ith line is cij ≤ 10000.
Output
Display yes if it is possible to do the task with cost zero; otherwise, display no.
Sample Input
3 2 2
0 2
1 1
2 0
Sample Output
yes
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
int s[105][105],vis[105];
int main()
{
int k,n,m;
while(~scanf("%d%d%d",&m,&n,&k))
{
memset(vis,0,sizeof(vis));
int cnt=0;
for(int i=0; i<m; i++)
for(int j=0; j<n; j++)
scanf("%d",&s[i][j]);
int flag;
int ff=0;
for(int i=0; i<m; i++)
{
flag=0;
for(int j=0; j<n; j++)
{
if(s[i][j]==0&&(!vis[j]))
{
flag=1;
cnt++;
vis[j]=1;
}
}
if(flag)
{
ff++;
flag=0;
}
}
if(cnt>=n&&ff<=k)
printf ("yes\n");
else
printf ("no\n");
}
return 0;
}