poj3740

poj3740

dfs

ContractedBlock.gif
ExpandedBlockStart.gif
View Code

#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

#define maxn 20
#define maxm 305

int n, m;
int map[maxn][maxm];
int num[maxn];
bool g[maxn][maxn];
int rownum[maxn];
bool found;

void input()
{
memset(num,
0, sizeof(num));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
int a;
scanf(
"%d", &a);
if (a == 0)
map[i][j]
= 0;
else
{
map[i][j]
= 1;
num[i]
++;
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
bool ok = true;
for (int k = 0; k < m; k++)
if (map[i][k] && map[j][k])
{
ok
= false;
break;
}
if (ok)
g[i][j]
= true;
else
g[i][j]
= false;
}
}

void dfs(int tot, int now, int ans)
{
if (found)
return;
if (now == n)
{
if (ans == m)
found
= true;
return;
}
dfs(tot, now
+ 1, ans);
bool ok = true;
for (int i = 0; i < tot; i++)
if (!g[rownum[i]][now])
{
ok
= false;
break;
}
if (ok)
{
rownum[tot]
= now;
dfs(tot
+ 1, now + 1, ans + num[now]);
}
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d%d", &n, &m) != EOF)
{
found
= false;
input();
dfs(
0, 0, 0);
if (found)
printf(
"Yes, I found it\n");
else
printf(
"It is impossible\n");
}
return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/110591.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • c语言sigaction,使用sigaction(),c[通俗易懂]

    c语言sigaction,使用sigaction(),c[通俗易懂]让我们试着了解修改后的代码版本会发生什么:#include#includevoidtermination_handler(intsignum){printf(“Hellofromhandler\n”);sleep(1);}intmain(void){//Structsthatwilldescribetheoldactionandthenewaction//ass…

    2022年5月26日
    43
  • VBA编程基础和编程环境(二)

    VBA编程基础和编程环境(二)    上一节中认识了Excel宏的基本样子,明白了VBA就是一门类似于C、JAVA、Python等编程语言,了解了VBA与宏的关系,本节开始学习VBA编程的基础知识和编程环境,是整个学习编程的基础。    一、VBA编程的几个重要概念    0、过程    把VBA代码按照一定顺序和逻辑排列用来完成Excel某个任务的过程,其实就是用VBA代码按照先后…

    2022年6月7日
    36
  • 不同火车车型的座位分布图片_火车硬卧号码分布图

    不同火车车型的座位分布图片_火车硬卧号码分布图本文内容全部来自于网络,记录在此,只是为后期便于寻找。————————————-分割线——————————–

    2022年8月1日
    14
  • org.apache.jasper.JasperException: An exception occurred processing JSP page

    JPivothadanerror…org.apache.jasper.JasperException:AnexceptionoccurredprocessingJSPpage/testpage.jspatline4441:42:43:44: 45: 46: 47: Stacktrace:org.apache.jasper.JasperEx

    2022年4月9日
    205
  • shell脚本编程100例pdf_linux基础命令表

    shell脚本编程100例pdf_linux基础命令表https://blog.csdn.net/yugemengjing/article/details/82469785https://blog.csdn.net/yugemengjing/article/details/824697851、编写helloworld脚本#!/bin/bash#编写helloworld脚本echo”HelloWorld!”2、通过位置变…

    2022年10月4日
    4
  • MMC 卡驱动分析[通俗易懂]

    MMC 卡驱动分析[通俗易懂]最近花时间研究了一下MMC卡驱动程序,开始在网上找了很多关于MMC卡驱动的分析文章,但大都是在描述各个层,这对于初学者来讲帮助并不大,所以我就打算把自己的理解写下来,希望对大家有用。个人觉得理解LINUX内核当中MMC/SD卡驱动程序构架是学习MMC卡驱动程序的重点,只有理解了它的基本框架或流程才能真正理解一个块设备驱动程序的写法,同时才能真正理解LINUX设备驱动模型是如

    2022年6月14日
    39

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号