题意:给你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. Beta冲刺Day4

    项目进展 李明皇 今天解决的进度 因服务器端未完成登录态维护,故无法进行前后端联动. 明天安排 前后端联动调试 林翔 今天解决的进度 因上课和实验室事务未完成登录态维护 明天安排 完成登录态维护 孙敏 ...

  2. 【iOS】swift 枚举

    枚举语法 你可以用enum开始并且用大括号包含整个定义体来定义一个枚举: enum SomeEnumeration { // 在这里定义枚举 } 这里有一个例子,定义了一个包含四个方向的罗盘: enu ...

  3. raid5 阵列硬盘离线数据恢复成功案例

    数据恢复故障描述: 某研究院 DELL 磁盘阵列崩溃,内置15块1TB硬盘搭建的RAID5阵列.一开始有一块硬盘离线,在更换新硬盘进行同步的过程中,第二块磁盘指示灯报警,同步失败,阵列无法正常工作. ...

  4. linux的链接工具secure设置字体大小和颜色

  5. LR之error(一)

    1 录制时频繁卡死的解决方案 添加数据保护 路径:计算机--高级系统设置(环境变量设置的上级窗口)--高级--设置--数据执行保护 更改LR录制设置,将run-time setting的brower改 ...

  6. 鼠标滑过切换div显示(鼠标事件)

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  7. ASP.NET 访问项目网站以外的目录文件

    简单的说,可以通过在 IIS 添加虚拟目录的方法做到,获取访问路径的时候就用 HttpContext.Current.Server.MapPath("~/xxx"); 的方式. 下 ...

  8. Python内置函数(58)——input

    英文文档: input([prompt]) If the prompt argument is present, it is written to standard output without a ...

  9. python 字符串的方法

    capitalize() 把字符串的第一个字符改为大写 casefold() 把整个字符串的所有字符改为小写 center(width) 将字符串居中,并使用空格填充至长度 width 的新字符串 c ...

  10. Linux实战案例(2)实例讲解使用软连接的场景和过程

    =================================== 使用场景:使用软连接简化版本切换动作 进入操作目录, cd /opt/modules/ ==================== ...