题目链接:

http://acm.hust.edu.cn/vjudge/problem/88634

Facility Locations

Time Limit: 3000MS

题意

给你一个m*n的矩阵,上面的数满足cij ≤ ci′j + ci′j′ + cij′。现在要选出k行,使得这k行上面的0刚好能够覆盖所有的列。

样例

sample input

3 2 2

0 2

1 1

2 0

3 3 2

0 2 2

1 1 1

2 2 0

sample output

yes

no

题解

“cij ≤ ci′j + ci′j′ + cij′”决定:如果两行在同一列都有零,那么这两行其他列的零的分布情况也会完全相同。所以我们可以枚举每一列,如果该列我们还没标记过,就任意选一个在该列为0的行(如果一个都找不到,那肯定无解),并标记该行其他列为0的位置,然后继续做,如果最后选k个以内就能做完,那么就输出yes,否则输出no。

代码

#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++) typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII; const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8; //start---------------------------------------------------------------------- const int maxn=111; int vis[maxn];
int arr[maxn][maxn];
int n,m,k; int main() {
while(scanf("%d%d%d",&n,&m,&k)==3){
rep(i,1,n+1){
rep(j,1,m+1){
scanf("%d",&arr[i][j]);
}
}
clr(vis,0);
int cnt=0,su=1;
rep(j,1,m+1){
if(vis[j]) continue;
rep(i,1,n+1){
if(arr[i][j]==0){
vis[j]=1;
cnt++;
rep(k,1,m+1){
if(arr[i][k]==0) vis[k]=1;
}
break;
}
}
if(!vis[j]){
su=0; break;
}
}
if(!su||cnt>k) puts("no");
else puts("yes");
}
return 0;
} //end-----------------------------------------------------------------------

最新文章

  1. matlab中pcolorh函数作用
  2. linux常用命令-用户管理命令
  3. 存储过程详解与java调用(转)
  4. tomcat源码剖析
  5. 视图(View)与部分视图(Partial View)之间数据传递
  6. Android中View的绘制过程 onMeasure方法简述 附有自定义View例子
  7. An Implementation of Double-Array Trie
  8. Python笔记本
  9. UNIX网络编程——网络IPC:套接字
  10. Java包的命名规则
  11. Chrome Apps将可以打包成iOS或Android应用
  12. mysql配置优化测试
  13. hdu5072(鞍山regional problem C):容斥,同色三角形模型
  14. 第九十一节,html5+css3pc端固定布局,完成首页
  15. mongoDB7--游标cursor
  16. XML读取两种方法
  17. [模拟赛] T2 不等数列
  18. MyDAL - .Where() 之 .WhereSegment 根据条件 动态设置 Select查询条件 使用
  19. python基础一 ------字符串的多种分隔符分隔
  20. Luncene介绍

热门文章

  1. windows 10 安装node.js
  2. 中国软件大会上大快搜索入选中国数字化转型TOP100服务商
  3. Spark运行模式_local(本地模式)
  4. s3c2440串口详解
  5. ruby中的字符串分隔符--split
  6. pyhton新手学习之增删改查
  7. SQL Server服务器角色和数据库角色描述
  8. Go Web 问题集-持续更新
  9. (数据科学学习手札44)在Keras中训练多层感知机
  10. 北京Uber优步司机奖励政策(1月27日)