【习题 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 ...
随机推荐
- 多client并发登录
//LoginClient.java package mySocket; import java.io.BufferedReader; import java.io.InputStreamReader ...
- vim使用(二):经常使用功能
1. vim经常使用功能 vim的经常使用功能.包含块的选择.复制,多文件的编辑.多窗体等功能. 2. vim块选择 块选择是将文档中的一块能够选择复制,粘贴,不用整行的处理. 按下 v , V . ...
- vue9 计算属性 computed
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- LVDS原理及设计指南
LVDS是一种低摆幅的差分信号技术,它使得信号能在差分PCB 线对或平衡电缆上以 几百Mbps的速率传输,其低压幅和低电流驱动输出实现了低噪声和低功耗. IEEE 在两个标准中对LVDS ...
- 104.virtual虚函数多态与异构数据结构
#include "mainwindow.h" #include <QApplication> #include <list> #include <Q ...
- java 文件读写demo
分析错误日志: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public ...
- 基于 Web 的 Go 语言 IDE - Wide 1.2.0 发布!
Wide 是什么 Wide 是一个基于 Web 的 Go 语言团队 IDE. 在线开发:打开浏览器就可以进行开发.全快捷键 智能提示:代码自动完成.查看表达式.编译反馈.Lint 实时运行:极速编译. ...
- Ubuntu16.04+Gnome3 锁定屏幕快捷键无效解决办法
Ubuntu16.04 桌面环境通过Ubuntu server和后安装的Gnome3 桌面环境实现,安装完以后发现锁定屏幕快捷键无效,系统设置=>键盘=>快捷中 锁屏快捷键已经存在Supe ...
- Python环境搭建—安利Python小白的Python安装详细教程
人生苦短,我用Python.众所周知,Python目前越来越火,学习Python的小伙伴也越来越多.最近看到群里的小伙伴经常碰到不会安装Python或者不知道去哪下载Python安装包等系列问题,为了 ...
- webpack4强势来袭
# Webpack4## 安装> webpack 4默认不需要配置文件(它吸收了Parcel的思想,零配置)> - npm i -D webpack> - npm i -D webp ...