【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

每次搜素要往下还是要往右摆。
然后维护一下让每个下标只出现一次就可以了。
=>作为剪枝条件

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
爆搜。
把每一行、每一列都排满。
然后枚举当前格子是往下排还是往右排
*/
#include <bits/stdc++.h>
using namespace std; const int N = 10; int a[N][N];
int bo[N][N],now[N][N];
int cnt[100],ans; void Init(){
int cnt = 1;
for (int i = 0;i <= 6;i++){
for (int j = i;j <= 6;j++){
bo[i][j] = cnt++;
}
}
} bool out(){
for (int i = 1;i <=7;i++){
for (int j = 1;j <= 8;j++)
cout <<setw(4)<<now[i][j];
cout << endl;
}
cout << endl << endl;
return true;
} void dfs(int x,int y){
if (y==9){
if (x==7){
ans++;
out();
return;
}
dfs(x+1,1);
return;
}
if (now[x][y]!=0){
dfs(x,y+1);
return;
}
//向下
if (x+1<=7){
int tx = min(a[x+1][y],a[x][y]),ty = max(a[x+1][y],a[x][y]);
now[x+1][y] = now[x][y] = bo[tx][ty];
cnt[bo[tx][ty]]++;
if (cnt[bo[tx][ty]]==1)dfs(x,y+1);
cnt[bo[tx][ty]]--;
now[x+1][y] = now[x][y] = 0;
}
//向右
if (y+1<=8 && now[x][y+1]==0){
int tx = min(a[x][y+1],a[x][y]),ty = max(a[x][y+1],a[x][y]);
now[x][y+1] = now[x][y] = bo[tx][ty];
cnt[bo[tx][ty]]++;
if (cnt[bo[tx][ty]]==1)dfs(x,y+1);
cnt[bo[tx][ty]]--;
now[x][y+1] = now[x][y] = 0;
}
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
Init();
int Kase = 0;
while (cin >> a[1][1]){
if (Kase>0){
cout << endl<<endl<<endl<<endl<<endl;
}
ans = 0;
for (int j = 2;j <= 8;j++) cin >> a[1][j];
for (int i = 2;i <= 7;i++)
for (int j = 1;j <= 8;j++)
cin >> a[i][j]; cout <<"Layout #"<<++Kase<<":"<<endl<<endl<<endl;
for (int i = 1;i <= 7;i++){
for (int j = 1;j <= 8;j++){
cout <<setw(3)<<a[i][j];
}
cout << endl;
}
cout << endl;
cout <<"Maps resulting from layout #"<<Kase<<" are:"<<endl<<endl<<endl;
dfs(1,1);
cout <<"There are "<<ans<<" solution(s) for layout #"<<Kase<<"."<<endl;
}
return 0;
}

【习题 7-3 UVA - 211】The Domino Effect的更多相关文章

  1. UVA 211 The Domino Effect 多米诺效应 (回溯)

    骨牌无非两种放法,横着或竖着放,每次检查最r,c最小的没访问过的点即可.如果不能放就回溯. 最外面加一层认为已经访问过的位置,方便判断. #include<bits/stdc++.h> ; ...

  2. UVA - 211 The Domino Effect(多米诺效应)(dfs回溯)

    题意:根据多米诺骨牌的编号的7*8矩阵,每个点可以和相邻的点组成的骨牌对应一个编号,问能形成多少种由编号组成的图. 分析:dfs,组成的图必须有1~28所有编号. #pragma comment(li ...

  3. uva 211(dfs)

    211 - The Domino Effect Time limit: 3.000 seconds A standard set of Double Six dominoes contains 28 ...

  4. CF 405B Domino Effect(想法题)

    题目链接: 传送门 Domino Effect time limit per test:1 second     memory limit per test:256 megabytes Descrip ...

  5. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  6. POJ 1135 Domino Effect(Dijkstra)

    点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...

  7. POJ 1135 Domino Effect (spfa + 枚举)- from lanshui_Yang

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  8. UVA211-The Domino Effect(dfs)

    Problem UVA211-The Domino Effect Accept:536  Submit:2504 Time Limit: 3000 mSec  Problem Description ...

  9. POJ 1135 Domino Effect (Dijkstra 最短路)

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9335   Accepted: 2325 Des ...

  10. POJ 1135.Domino Effect Dijkastra算法

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10325   Accepted: 2560 De ...

随机推荐

  1. RvmTranslator7.0-IFC

    RvmTranslator7.0-IFC eryar@163.com RvmTranslator can translate the RVM file exported by AVEVA Plant( ...

  2. 用 shell 获取本机的网卡名称

    用 shell 获取本机的网卡名称 # 用 shell 获取本机的网卡名称 ls /sys/class/net # 或者 ifconfig | grep "Link" | awk ...

  3. js阻止默认事件与js阻止事件冒泡

    e.stopPropagation(); //阻止事件冒泡 功能:停止事件冒泡 function stopBubble(e) { // 如果提供了事件对象,则这是一个非IE浏览器 if ( e &am ...

  4. SQL Server 2005高可用性模式下创建数据库镜像

    SQL Server 2005高可用性模式下创建数据库镜像   高可用性模式下创建数据库镜像 第一步: --创建镜像用数据库-在主服务器上操作 create database db_mirror on ...

  5. 分享vue ui时间组件用法

    //js code var jiaban = { template:` <i-form v-ref:form_jb :model="form_jb" :rules=" ...

  6. comm---两个文件之间的比较

    comm命令可以用于两个文件之间的比较,它有一些选项可以用来调整输出,以便执行交集.求差.以及差集操作. 交集:打印出两个文件所共有的行. 求差:打印出指定文件所包含的且不相同的行. 差集:打印出包含 ...

  7. 数据持久化-存取方式总结&应用沙盒&文件管理NSFileManager

    iOS应用数据存储的常用方式:  1.XML属性列表   (plist归档)  2.NSUserDefaults (偏好设置)  3.NSKeyedArchiver  归档(加密形式)  4.SQLi ...

  8. IDEA全局更改统一编码为utf-8

    File -> Other Settings->Deaault Settings->Settings->File Encodings -> Defaule encodin ...

  9. Android底层驱动开发(一)

    1   Android为什么要增加硬件抽象层HAL A    统一硬件调用接口.所以利用HAL屏蔽linux驱动的复杂不统一的接口 B   解决GPL版权问题,因为linux内核基于GPL协议.这个G ...

  10. (诡异Floyd&amp;自环)MZ Training 2014 #15 E题(POJ 2240)

    你们见过这么诡异的FLOYD吗? 先上题. [Description] 货币的汇率存在差异.比如,如果1美元购买0.5英镑,1英镑买10法郎.而1法国法郎买0.21美元.然后,通过转换货币,一个聪明的 ...