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
HINT
Source
题意:从n行m列的矩阵中选出至多k行,使得每一列都有0
思路:暴力
#include <iostream> #include <stdio.h> #include <string.h> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <math.h> #include <bitset> #include <algorithm> #include <climits> using namespace std; #define LS 2*i #define RS 2*i+1 #define UP(i,x,y) for(i=x;i<=y;i++) #define DOWN(i,x,y) for(i=x;i>=y;i--) #define MEM(a,x) memset(a,x,sizeof(a)) #define W(a) while(a) #define gcd(a,b) __gcd(a,b) #define LL long long #define N 25 #define MOD 1000000007 #define INF 0x3f3f3f3f #define EXP 1e-8 int n,m,k; int vis[105]; int main() { int i,j,k,x; W(~scanf("%d%d%d",&n,&m,&k)) { int mm = 0,kk = 0; MEM(vis,0); UP(i,1,n) { int flag = 0; UP(j,1,m) { scanf("%d",&x); if(x || vis[j]) continue; if(!flag) kk++; flag = 1; vis[j] = 1; mm++; } } if(mm == m&&kk<=k) puts("yes"); else puts("no"); } return 0; }