【习题 7-3 UVA - 211】The Domino Effect
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
每次搜素要往下还是要往右摆。
然后维护一下让每个下标只出现一次就可以了。
=>作为剪枝条件
【代码】
/*
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的更多相关文章
- UVA 211 The Domino Effect 多米诺效应 (回溯)
骨牌无非两种放法,横着或竖着放,每次检查最r,c最小的没访问过的点即可.如果不能放就回溯. 最外面加一层认为已经访问过的位置,方便判断. #include<bits/stdc++.h> ; ...
- UVA - 211 The Domino Effect(多米诺效应)(dfs回溯)
题意:根据多米诺骨牌的编号的7*8矩阵,每个点可以和相邻的点组成的骨牌对应一个编号,问能形成多少种由编号组成的图. 分析:dfs,组成的图必须有1~28所有编号. #pragma comment(li ...
- uva 211(dfs)
211 - The Domino Effect Time limit: 3.000 seconds A standard set of Double Six dominoes contains 28 ...
- CF 405B Domino Effect(想法题)
题目链接: 传送门 Domino Effect time limit per test:1 second memory limit per test:256 megabytes Descrip ...
- [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)
Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...
- POJ 1135 Domino Effect(Dijkstra)
点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...
- 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 ...
- UVA211-The Domino Effect(dfs)
Problem UVA211-The Domino Effect Accept:536 Submit:2504 Time Limit: 3000 mSec Problem Description ...
- POJ 1135 Domino Effect (Dijkstra 最短路)
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9335 Accepted: 2325 Des ...
- POJ 1135.Domino Effect Dijkastra算法
Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10325 Accepted: 2560 De ...
随机推荐
- Cocos2d-x学习笔记(十四)CCAutoreleasePool具体解释
原创文章,转载请注明出处:http://blog.csdn.net/sfh366958228/article/details/38964637 前言 之前学了那么多的内容.差点儿全部的控件都要涉及内存 ...
- wcf rest系列文章
http://www.cnblogs.com/artech/archive/2012/02/15/wcf-rest.html 需要注意的是,发布的服务,可以在web behavior中指定显示help ...
- POJ 3184 DP+剪枝
思路: 先找到每i头奶牛能在的位置 (一段区间) 记为L[i]和R[i] f[j]表示在位置j取到的最小值 每回在范围内更新一哈 //By SiriusRen #include <cstdio& ...
- centos yum 安装php7.2
yum -y remove php* rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm r ...
- Linux运维管理的必备工具
一.统一账号管理 1.LDAP 统一管理各种平台帐号和密码,包括但不限于各种操作系统(Windows.Linux),Linux系统sudo集成,系统用户分组,主机登入限制等:可与Apache,HTTP ...
- 创建maven项目pom.xml出现错误(依赖Missing)
Maven的依赖问题 在聚合模块时候,发现在父工程目录中的依赖存在一些问题.一开始是${pagehelper.version},后来将版本直接填写相应的版本如图下 依赖添加失败 * 在父工程的jar包 ...
- jquery2.0.3 全部源码
/*! * Includes Sizzle.js 选择器,独立的库 * http://sizzlejs.com/ */ (function( window, undefined ) { //" ...
- 具有可视化的功能的一款开源软件Gource
今天为大家介绍一个非常有趣儿的开源软件,Gource可以将代码版本控制系统里面的日志全部可视化,也就是说可以看见每个成员在系统里面提交代码的行为,Gource目前支持git,hg,svn. 650) ...
- JQ 实施编辑 (clone()复制行||双击编辑)
//代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- C#开发 —— 基础知识
C# 用于开发可以运行在 .Net 平台上的应用程序,C# 本身只是一种语言,尽管它是用于生成面向 .Net 环境的代码,但它本身不是 .Net 的一部分 Console.WriteLine 命名空间 ...