[poj3740]Easy Finding_状态压缩_dfs
Easy Finding poj-3470
题目大意:给你一个01矩阵,问能否选出一些行,使得这些行所新组成的01矩阵每列中有且只有1个1。
注释:1<=行数<=16,1<=列数<=300.
想法:对于一个单独的01矩阵来讲,我们可以用一个数表示其中的每一行,然后暴力枚举每一行选取情况即可。
最后,附上丑陋的代码... ...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int c[320];
bool flag;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(c,0,sizeof(c));
flag=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
int a;
scanf("%d",&a);
c[j]+=(a<<(i-1));
}
}
for(int s=0;s<(1<<n);s++)
{
for(int j=1;j<=m;j++)
{
int middle;
middle=s&c[j];
if(middle!=0 && (middle&(middle-1))==0)
{
if(j==m)
flag=1;
else continue;
}
else break;
}
if(flag)
break;
}
if(flag) printf("Yes, I found it\n");
else printf("It is impossible\n");
}
return 0;
}
小结:位运算的优先级是滞后的,但是sublime里会吹warning,如果利用优先级的话。
[poj3740]Easy Finding_状态压缩_dfs的更多相关文章
- Marriage Ceremonies(状态压缩dp)
Marriage Ceremonies Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu ...
- Number Game_状态压缩
Description Christine and Matt are playing an exciting game they just invented: the Number Game. The ...
- UVALive 3953 Strange Billboard (状态压缩+枚举)
Strange Billboard 题目链接: http://acm.hust.edu.cn/vjudge/contest/129733#problem/A Description The marke ...
- poj 2441 Arrange the Bulls(状态压缩dp)
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...
- 【BZOJ2734】【HNOI2012】集合选数(状态压缩,动态规划)
[BZOJ2734][HNOI2012]集合选数(状态压缩,动态规划) 题面 Description <集合论与图论>这门课程有一道作业题,要求同学们求出{1, 2, 3, 4, 5}的所 ...
- hdu 4352 数位dp + 状态压缩
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- POJ-1143(状态压缩)
Number Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3432 Accepted: 1399 Descripti ...
- hdu 4352 XHXJ's LIS 数位dp+状态压缩
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others ...
- hdu 4352 XHXJ's LIS (数位dp+状态压缩)
Description #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully readin ...
随机推荐
- phpcmsv9更换模板介绍
先分享下大概的步骤: 1.上传模版文件到服务器:2.在站点管理 里边[模板风格配置]选择新模板:3.设置不同模型对应模板:4.修改现有的栏目,匹配新模板:5.更新栏目缓存.系统缓存,更新HTML静态页 ...
- 【dedecms】DEDE列表页调用文章内容第一张图片(非缩略图)方法
打开 ../ include/ common.func.php 添加代码 //将缩放图转变为文章第一张图片 function firstimg($str_pic) { $str_sub=substr( ...
- 求sum=1+111+1111+........+1....111 .
1,思路 大数相加,若直接使用int,或者long都会超出长度,因此考虑使用String存储. 2,代码 public class LargeNumAdd { public static void m ...
- 错误代码: 1248 Every derived table must have its own alias
1.错误描述 1 queries executed, 0 success, 1 errors, 0 warnings 查询:SELECT stu_id, (SELECT stu_name FROM t ...
- Java注释分类
Java注释分类 1.单行注释 //打印结果 System.out.println("结果是:"+result); 2.多行注释 /** * @autho ...
- ASP.NET CORE的Code Fist后Models更改了怎么办?
上次我写到MVC的code fist后,自动生成数据库并自动生成web页面了 点击打开链接 那么随着项目需求的逐步明确,model变化了怎么办呢?其实和上次一样的,有两条关键的语句要记住 Add-Mi ...
- Rational Rose_2007的下载、安装与破解--UML建模软件
一.下载Rational.Rose_2007安装包与破解文件 对于Rational.Rose_2007,您可以到我的百度网盘计算机相关专业所用软件---百度云链接下载下载,另外附上安装需要的通行证(破 ...
- RobotFramework下的http接口自动化Set Request Body 关键字的使用
Set Request Body关键字用来设置http 请求时的body 信息,尤其是在post 请求时,经常需要用到这个关键字. 该关键字接收一个参数,[ body ] 示例1:登录博客园(http ...
- 【BZOJ4195】【NOI2015】程序自动分析(并查集)
[BZOJ4195][NOI2015]程序自动分析(并查集) 题面 Description 在实现程序自动分析的过程中,常常需要判定一些约束条件是否能被同时满足. 考虑一个约束满足问题的简化版本:假设 ...
- Java中高级面试题
一.基础知识: 1)集合类:List和Set比较,各自的子类比较(ArrayList,Vector,LinkedList:HashSet,TreeSet): 2)HashMap的底层实现,之后会问Co ...