题意:给你28个多米勒牌,要求刚好铺满一个7x8的图,输出所有答

案。每个牌只能使用一次

思路:

对每个位置分别搜索其右边 和 下边。

但是在中途,细节上有点问题。最开始想的是搜到最后一个点输出答案,但总是有问题。然后搜索部分换了个姿势,记录以使用的牌数,终于AC。感觉 - -自己好坑

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
typedef long long ll;
using namespace std;
const int inf = 0x3f3f3f3f;
int all; int vis[10][10];
int ans[10][10];
int p[10][10];
int pip[10][10];
int vis_pip[30][30];
int dir[2][2] = {{0,1},{1,0}}; void ini()
{
int tt = 1;
for(int i = 0; i < 7; i++)
for(int j = i; j < 7; j++)
{
pip[i][j] = pip[j][i] = tt++;
}
return;
} void dfs(int cur,int num)
{ int x = cur/8;
int y = cur%8;
if(num == 28) //搜满28个
{
for(int i = 0; i < 7; i++)
{
for(int j = 0; j < 8; j++)
{
printf("%4d",ans[i][j]);
}
printf("\n");
}
all ++;
printf("\n");
return ;
}
if(vis[x][y])
{
dfs(cur+1,num);
return ;
}
if(x > 6 || y > 7)
return ;
for(int i = 0;i < 2;i++)
{
if(i == 0 && y == 7) continue;
if(i == 1 && x == 6) continue;
int tx = x + dir[i][0];
int ty = y + dir[i][1];
if(vis[tx][ty] || vis_pip[p[x][y]][p[tx][ty]])
continue;
vis[x][y] = vis[tx][ty]= vis_pip[p[x][y]][p[tx][ty]] = vis_pip[p[tx][ty]][p[x][y]] = 1;
ans[x][y] = ans[tx][ty] = pip[p[x][y]][p[tx][ty]];
dfs(cur+1,num+1);
vis[x][y] = vis[tx][ty]= vis_pip[p[x][y]][p[tx][ty]] = vis_pip[p[tx][ty]][p[x][y]] = 0;
}
return ;
} int main()
{
int cas = 1;
ini();
// freopen("in.txt","r",stdin);
while(scanf("%d%d%d%d%d%d%d%d",&p[0][0],&p[0][1],&p[0][2],&p[0][3],&p[0][4],&p[0][5],&p[0][6],&p[0][7]) != EOF)
{
for(int i = 1; i < 7; i++)
for(int j = 0; j < 8; j++)
{
scanf("%d",&p[i][j]);
}
if(cas!= 1)
printf("\n\n\n");
memset(vis,0,sizeof(vis));
memset(vis_pip,0,sizeof(vis_pip));
printf("Layout #%d:\n\n",cas);
for(int i = 0; i < 7; i++)
{
for(int j = 0; j <8; j++)
{
printf("%4d",p[i][j]);
}
printf("\n");
}
printf("\n");
printf("Maps resulting from layout #%d are:\n\n",cas);
all = 0; dfs(0,0);
printf("There are %d solution(s) for layout #%d.\n",all,cas++);
}
return 0;
}

  

习题 7-3 uva211的更多相关文章

  1. Sharepoint学习笔记—习题系列--70-576习题解析 --索引目录

        Sharepoint学习笔记—习题系列--70-576习题解析  为便于查阅,这里整理并列出了70-576习题解析系列的所有问题,有些内容可能会在以后更新. 需要事先申明的是:     1. ...

  2. 《python核心编》程课后习题——第三章

    核心编程课后习题——第三章 3-1 由于Python是动态的,解释性的语言,对象的类型和内存都是运行时确定的,所以无需再使用之前对变量名和变量类型进行申明 3-2原因同上,Python的类型检查是在运 ...

  3. 习题 5: 更多的变量和打印 | 笨办法学 Python

    一. 简述 “格式化字符串(format string)” -  每一次你使用 ' ’ 或 " " 把一些文本引用起来,你就建立了一个字符串. 字符串是程序将信息展示给人的方式. ...

  4. 【WebGoat习题解析】Parameter Tampering->Bypass HTML Field Restrictions

    The form below uses HTML form field restrictions. In order to pass this lesson, submit the form with ...

  5. python核心编程(第二版)习题

    重新再看一遍python核心编程,把后面的习题都做一下.

  6. SQL简单语句总结习题

    创建一个表记员工个人信息: --创建一个表 create table plspl_company_info( empno ) not null, ename ) not null, job ), ma ...

  7. 《Python核心编程》部分代码习题实践(持续更新)

    第三章 3-10 交换异常处理方式 代码: #makeTextFile.py #!/usr/bin/env python 'makeTextFile.py' import os ls = os.lin ...

  8. web实验指导书和课后习题参考答案

    实验指导书 :http://course.baidu.com/view/daf55bd026fff705cc170add.html 课后习题参考答案:http://wenku.baidu.com/li ...

  9. 《C++primer》v5 第1章 开始 读书笔记 习题答案

    从今天开始在博客里写C++primer的文字.主要以后面的习题作业为主,会有必要的知识点补充. 本人也是菜鸟,可能有不对之处,还望指出. 前期内容可能会比较水. 1.1略 1.2略 1.3 cin和c ...

随机推荐

  1. Flask 扩展 自定义扩展

    创建一个为视图访问加日志的扩展Flask-Logging,并从中了解到写Flask扩展的规范. 创建工程 先创建一个工程,目录结构如下: flask-logging/ ├ LICENSE # 授权说明 ...

  2. JAVA中最容易让人忽视的基础。

    可能很多找编程工作的人在面试的时候都有这种感受,去到一个公司填写面试试题的时候,多数人往往死在比较基础的知识点上.不要奇怪,事实就是如此一般来说,大多数公司给出的基础题大概有122道,代码题19道左右 ...

  3. AWK读书笔记

    1.awk 'parttern {action}' filename 从文件中逐行读取并匹配parttern,若匹配成功执行action否则读取下一行. parttern和action都可选,若省略p ...

  4. vue中一个dom元素可以绑定多个事件?

    其实这个问题有多个解决方法的  这里提出两点 第一种 第二种 现在dom上绑定一个 然后在你的methods中直接调用 如果要传参数  这时候千万别忘记 原创 如需转载注明出处 谢谢

  5. 解决SoapFault (looks like we got no XML document)问题

    今天在调试项目的时候出现下面的错误信息: SoapFault looks like we got no XML document (D:\phpStudy\WWW\self.shop.xunmall. ...

  6. egg.js 的优缺点

    egg.js 的优缺点 优点 所有的 web开发的点都考虑到了 agent 很有特色 文件夹规划到位 扩展能力优秀 缺点 最大的问题在于: 使用 loader 加载之后,失去了代码提示的能力 监控和运 ...

  7. Python内置函数(26)——enumerate

    英文文档: enumerate(iterable, start=0) Return an enumerate object. iterable must be a sequence, an itera ...

  8. 前端基础之html-Day12

    1.web服务本质 import socket def main(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bi ...

  9. Mosquito集群模式

    参考链接: http://blog.csdn.net/z729685731/article/details/70142182 http://blog.csdn.net/yuhaiyang457288/ ...

  10. spring-oauth-server实践:授权方式四:client_credentials 模式的refresh_token?

    spring-oauth-server入门(1-13)授权方式四:client_credentials 模式的refresh_token? 有效期内的反复申请access_token获取失效日期不变! ...