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

【题意】

在这里输入题意

【题解】

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

【代码】

  1. /*
  2. 1.Shoud it use long long ?
  3. 2.Have you ever test several sample(at least therr) yourself?
  4. 3.Can you promise that the solution is right? At least,the main ideal
  5. 4.use the puts("") or putchar() or printf and such things?
  6. 5.init the used array or any value?
  7. 6.use error MAX_VALUE?
  8. 7.use scanf instead of cin/cout?
  9. 8.whatch out the detail input require
  10. */
  11. /*
  12. 一定在这里写完思路再敲代码!!!
  13. 爆搜。
  14. 把每一行、每一列都排满。
  15. 然后枚举当前格子是往下排还是往右排
  16. */
  17. #include <bits/stdc++.h>
  18. using namespace std;
  19. const int N = 10;
  20. int a[N][N];
  21. int bo[N][N],now[N][N];
  22. int cnt[100],ans;
  23. void Init(){
  24. int cnt = 1;
  25. for (int i = 0;i <= 6;i++){
  26. for (int j = i;j <= 6;j++){
  27. bo[i][j] = cnt++;
  28. }
  29. }
  30. }
  31. bool out(){
  32. for (int i = 1;i <=7;i++){
  33. for (int j = 1;j <= 8;j++)
  34. cout <<setw(4)<<now[i][j];
  35. cout << endl;
  36. }
  37. cout << endl << endl;
  38. return true;
  39. }
  40. void dfs(int x,int y){
  41. if (y==9){
  42. if (x==7){
  43. ans++;
  44. out();
  45. return;
  46. }
  47. dfs(x+1,1);
  48. return;
  49. }
  50. if (now[x][y]!=0){
  51. dfs(x,y+1);
  52. return;
  53. }
  54. //向下
  55. if (x+1<=7){
  56. int tx = min(a[x+1][y],a[x][y]),ty = max(a[x+1][y],a[x][y]);
  57. now[x+1][y] = now[x][y] = bo[tx][ty];
  58. cnt[bo[tx][ty]]++;
  59. if (cnt[bo[tx][ty]]==1)dfs(x,y+1);
  60. cnt[bo[tx][ty]]--;
  61. now[x+1][y] = now[x][y] = 0;
  62. }
  63. //向右
  64. if (y+1<=8 && now[x][y+1]==0){
  65. int tx = min(a[x][y+1],a[x][y]),ty = max(a[x][y+1],a[x][y]);
  66. now[x][y+1] = now[x][y] = bo[tx][ty];
  67. cnt[bo[tx][ty]]++;
  68. if (cnt[bo[tx][ty]]==1)dfs(x,y+1);
  69. cnt[bo[tx][ty]]--;
  70. now[x][y+1] = now[x][y] = 0;
  71. }
  72. }
  73. int main(){
  74. #ifdef LOCAL_DEFINE
  75. freopen("rush_in.txt", "r", stdin);
  76. #endif
  77. ios::sync_with_stdio(0),cin.tie(0);
  78. Init();
  79. int Kase = 0;
  80. while (cin >> a[1][1]){
  81. if (Kase>0){
  82. cout << endl<<endl<<endl<<endl<<endl;
  83. }
  84. ans = 0;
  85. for (int j = 2;j <= 8;j++) cin >> a[1][j];
  86. for (int i = 2;i <= 7;i++)
  87. for (int j = 1;j <= 8;j++)
  88. cin >> a[i][j];
  89. cout <<"Layout #"<<++Kase<<":"<<endl<<endl<<endl;
  90. for (int i = 1;i <= 7;i++){
  91. for (int j = 1;j <= 8;j++){
  92. cout <<setw(3)<<a[i][j];
  93. }
  94. cout << endl;
  95. }
  96. cout << endl;
  97. cout <<"Maps resulting from layout #"<<Kase<<" are:"<<endl<<endl<<endl;
  98. dfs(1,1);
  99. cout <<"There are "<<ans<<" solution(s) for layout #"<<Kase<<"."<<endl;
  100. }
  101. return 0;
  102. }

【习题 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. Android 勤用RXJava compose操作符消除重复代码

    相信小伙伴在使用RXJava与Retrofit请求网络时,都有遇到过这样的场景,在IO线程请求网络解析数据,接着返回主线程setData.更新View试图,那么也肯定熟悉下面这几句代码: .subsc ...

  2. C/C++(C++类与对象)

    构造器(constructor) 1.与类名相同,无返回,被系统生成对象时自动调用,用于初始化. 2.可以有参数,构造器的重载,有默认参数.重载和默认参数不能同时出现,但是一定要包含标配(无参数的构造 ...

  3. 《三》build 快速创建模块

    一.将build.php文件复制一份放在 application目录下 二.修改build.php文件代码 <?php return [ 'home' => [ //需要生成的目录 '__ ...

  4. java.sql.SQLException:错误 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    错误 方法 添加后面的内容即可

  5. 2018上半年GitHub上最热门的开源项目

    关注GitHub的人都知道,这个平台上面有太多优秀的值得学习的开源项目了,这里总结了2018上半年GitHub上最热门的开源项目. 1: tensorflow https://github.com/t ...

  6. ListView常用操作

    1.设置ListView只显示一列,并且每加一条记录是向下添加的. ListView添加方法:把View属性改成Details,再Columns属性中添加一列 然后用如下代码即可实现 ListView ...

  7. Android设计模式(七)--原型模式

    1.定义: 用原型实例指定创建对象种类,并通过拷贝这些原型创建新的对象. 2.目的: 从一个对象创建另外一个可定制的对象,而不须要知道不论什么创建细节. 3.作用: 3.1.简化对象的创建. 3.2 ...

  8. STL heap部分源代码分析

    本文假设你已对堆排序的算法有主要的了解. 要分析stl中heap的源代码的独到之处.最好的办法就是拿普通的代码进行比較.话不多说,先看一段普通的堆排序的代码: //调整大顶堆.使得结构合理 void ...

  9. POJ 2104 K-th Number 静态主席树(裸

    题目链接:点击打开链接 题意: 给定n长的序列.q个询问 以下n个数字给出序列 每一个询问[l, r] k ,输出该区间中第k大的数 先建一个n个节点的空树.然后每次从后往前新建一棵树,依附原来的空树 ...

  10. 修正EasyUI的BUG——Form中存在FileBox时的数据载入错误

    使用EasyUI载入服务端返回的数据时经常使用 $('#fm').form('load', row); 实现,既方便又简洁,可是.当Form中包括有FileBox时,代码就会报错,经过跟踪发现.由于E ...