[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 ...
随机推荐
- java.util.zip.ZipException:ZIP file must have at least one entry
1.错误描述 java.util.zip.ZipException:ZIP file must have at least one entry 2.错误原因 由于在导出文件时,要将导出的文件压缩到压缩 ...
- JavaScript禁止浏览器默认行为
JavaScript禁止浏览器默认行为 1.实现源码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&quo ...
- freemarker.template.TemplateException:Error executing macro:mainSelect
1.错误描述 freemarker.template.TemplateException:Error executing macro:mainSelect require parameter:id i ...
- 使用AspNetPager控件分页
页面后台写法 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindData(); } } pro ...
- WPF基础篇之命名空间
WPF中XAML与C#一样,也有自己独立的编译器.XAML会被解析和编译,最终形成微软的中间语言存储在程序集中.在解析和编译XAML的语言过程中,我们经常需要告诉编译器一些重要的信息,比如XAML代码 ...
- 浏览器之window对象--javascript
window对象代表打开的浏览器窗口,是Web浏览器所有内容的主容器.window对象是整个对象链条结构的最高层,是其他对象的父对象,在调用window对象的方法和属性时,可以省略window对象的引 ...
- SDP(11):MongoDB-Engine功能实现
根据上篇关于MongoDB-Engine的功能设计方案,我们将在这篇讨论里进行功能实现和测试.下面是具体的功能实现代码:基本上是直接调用Mongo-scala的对应函数,需要注意的是java类型和sc ...
- bzoj2969 矩形粉刷
学习一波用markdown写题解的姿势QAQ 题意 给你一个w*h的矩形网格,每次随机选择两个点,将以这两个点为顶点的矩形内部的所有小正方形染黑,问染了k次之后期望有多少个黑色格子. 分析 一开始看错 ...
- 【BZOJ1095】捉迷藏(动态点分治)
[BZOJ1095]捉迷藏(动态点分治) 题面 BZOJ 题解 动态点分治板子题 假设,不考虑动态点分治 我们来想怎么打暴力: \(O(n)DP\)求树的最长链 一定都会.不想解释了 所以,利用上面的 ...
- [HNOI2010]CHORUS 合唱队
题面 Bzoj Sol 简单\(DP\) # include <bits/stdc++.h> # define IL inline # define RG register # defin ...