【习题 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 ...
随机推荐
- 识别CentOS和Ubuntu的系统版本
识别CentOS和Ubuntu的系统版本1.用 lsb-release#!/bin/bashInstall_LSB(){ if [ "$PM" = "yum ...
- Java基本数据类型及字节
1.基本类型可以分为三类,字符类型char,布尔类型boolean以及数值类型byte.short.int.long.float.double.数值类型又可以分为整数类型byte.short.int. ...
- avalon 作用域
作用域绑定(ms-controller, ms-important) 如果一个页面非常复杂,就需要划分模块,每个模块交由不同的ViewModel去处理.我们就要用到ms-controller与ms-i ...
- 深入理解Android(5)——从MediaScanner分析Android中的JNI
前面几篇介绍了Android中的JNI和基本用法,这一篇我们通过分析Android源代码中的JNI实例,来对JNI部分做一个总结. 一.通向两个不同世界的桥梁 在前面我们说过,JNI就像一个桥梁,将J ...
- 安装完Python之后,如何设置Python环境变量
人生苦短,我用Python.最近有许多加群的萌新在咨询Python安装的事宜,Python安装问题不大,可以戳这篇文章:.本以为安装Python之后就可以万事大吉,高枕无忧了,往命令行中输入pytho ...
- HDU 3911 Black And White
Black And White Time Limit: 3000ms Memory Limit: 32768KB This problem will be judged on HDU. Origina ...
- CSUOJ 1555 Inversion Sequence
1555: Inversion Sequence Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 107 Solved: 34 Description ...
- nio实现文件读取写入数据库或文件
1.nio实现读取大文件,之后分批读取写入数据库 2.nio实现读取大文件,之后分批写入指定文件 package com.ally; import java.io.File; import java. ...
- 使用表单向action提交时出现 “Error setting expression 'button' with value……”
原因是,form中的组件设置了name属性,struts2会通过OGNL在action中找相应的属性. 如 <form action="login"> <intp ...
- [Python] Python Libs
The Python Standard Library has a lot of modules! To help you get familiar with what's available, he ...