题意:

象棋里的車可以吃横竖的車,题目加了一个墙,用于阻断攻击,问4x4的棋盘最多可以放多少只車,

思路:枚举每一个点,2^16次方种情况

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<sstream>
  4. #include<queue>
  5. #include<map>
  6. #include<memory.h>
  7. #include <math.h>
  8. #include<time.h>
  9. #include <stdlib.h>
  10. #include <algorithm>
  11. using namespace std;
  12. #define N 8
  13. int m[N][N];
  14. int vis[N];
  15. int n;
  16. int final = ;
  17. void dfs(int curLine, int curCol, int num)
  18. {
  19. if(curLine > n)
  20. {
  21. final = final < num ? num : final;
  22. return;
  23. }
  24. if(m[curLine][curCol] == )
  25. {
  26. if(curCol + > n)
  27. dfs(curLine + , , num);
  28. else
  29. dfs(curLine, curCol + , num);
  30. return;
  31. }
  32. int ok = ;
  33. for(int i = curLine - ; i >= ; i--)
  34. {
  35. if(m[i][curCol] == )
  36. break;
  37. if(m[i][curCol] == )
  38. {
  39. ok = ;
  40. break;
  41. }
  42. }
  43. for(int i = curCol - ; i >= &&ok; i--)
  44. {
  45. if(m[curLine][i] == )
  46. break;
  47. if(m[curLine][i] == )
  48. {
  49. ok = ;
  50. break;
  51. }
  52. }
  53. if(ok)
  54. {
  55. m[curLine][curCol] = ;
  56. if(curCol + > n)
  57. dfs(curLine + , , num + );
  58. else
  59. dfs(curLine, curCol + , num + );
  60. m[curLine][curCol] = ;
  61. }
  62. if(curCol + > n)
  63. dfs(curLine + , , num);
  64. else
  65. dfs(curLine, curCol + , num);
  66. }
  67.  
  68. int main(const int argc, char** argv)
  69. {
  70. //freopen("d:\\1.txt", "r", stdin);
  71. while (cin >> n && n)
  72. {
  73. final = ;
  74. memset(vis, , sizeof(vis));
  75. memset(m, -, sizeof(m));
  76. char c;
  77. for(int i = ; i <= n; i++)
  78. for(int j = ; j <= n; j++)
  79. {
  80. cin >> c;
  81. if(c == 'X')
  82. m[i][j] = ;
  83. else
  84. m[i][j] = ;
  85. }
  86. dfs(, , );
  87. cout << final << endl;
  88. }
  89. return ;
  90. }

uva-639-枚举的更多相关文章

  1. UVa 12169 (枚举+扩展欧几里得) Disgruntled Judge

    题意: 给出四个数T, a, b, x1,按公式生成序列 xi = (a*xi-1 + b) % 10001 (2 ≤ i ≤ 2T) 给出T和奇数项xi,输出偶数项xi 分析: 最简单的办法就是直接 ...

  2. UVa 140 (枚举排列) Bandwidth

    题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...

  3. UVa 1151 (枚举 + MST) Buy or Build

    题意: 平面上有n个点,现在要把它们全部连通起来.现在有q个套餐,如果购买了第i个套餐,则这个套餐中的点全部连通起来.也可以自己单独地建一条边,费用为两点欧几里得距离的平方.求使所有点连通的最小费用. ...

  4. UVA 639 (13.08.25)

     Don't Get Rooked  In chess, the rook is a piece that can move any number of squaresvertically or ho ...

  5. Even Parity UVA - 11464 (枚举)

    从来没有觉得枚举有多费脑子的.但是这道题还是很香的. 思路:就是非常简单的枚举啦.   从一般的枚举开始考虑.一般的做法就是在所有的格子中有两种状态1, 0. 而一共有225个格子,所有一共要枚举的情 ...

  6. UVa 1354 枚举子集 Mobile Computing

    只要枚举左右两个子天平砝码的集合,我们就能算出左右两个悬挂点到根悬挂点的距离. 但是题中要求找尽量宽的天平但是不能超过房间的宽度,想不到要怎样记录结果. 参考别人代码,用了一个结构体的vector,保 ...

  7. uva 639 Don't Get Rooked 变形N皇后问题 暴力回溯

    题目:跟N皇后问题一样,不考虑对角冲突,但考虑墙的存在,只要中间有墙就不会冲突. N皇后一行只能放一个,而这题不行,所以用全图暴力放棋,回溯dfs即可,题目最多就到4*4,范围很小. 刚开始考虑放一个 ...

  8. Uva 11754(枚举+中国剩余定理)

    #include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...

  9. 10年省赛-Greatest Number (二分+暴力) + 12年省赛-Pick apples(DP) + UVA 12325(暴力-2次枚举)

    题意:给你n个数,在里面取4个数,可以重复取数,使和不超过M,求能得到的最大的数是多少: 思路:比赛时,和之前的一个题目很像,一直以为是体积为4(最多选择四次)的完全背包,结果并不是,两两求和,然后二 ...

  10. UVa 10465 Homer Simpson (枚举)

    10465 - Homer Simpson Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onli ...

随机推荐

  1. 杭电 KazaQ's Socks

    KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbered from 1 to n in his cl ...

  2. Java8 (Function,Consumer,Predicate,Supplier)详解

    1. https://blog.csdn.net/lzm18064126848/article/details/70199769 1.1 https://blog.csdn.net/turbo_zon ...

  3. http协议详谈

    scheme - 定义因特网服务的类型.最常见的类型是 httphost - 定义域主机(http 的默认主机是 www)domain - 定义因特网域名,比如 runoob.comport - 定义 ...

  4. smarty学习——高级知识

    1.Objects 对象 smarty允许通过模板访问PHP对象.有两种方式来访问它们.一种是注册对象到模板,然后通过类似于用户自定义函数的形式来访问它. 另一种方法给模板分配对象,然后通过访问其它赋 ...

  5. python之 列表常用方法

    更多列表的使用方法和API,请参考Python文档:http://docs.python.org/2/library/functions.html append:用于在列表末尾追加新对象: # app ...

  6. RESTful 接口设计规范

    get 用来获取,post 用来新建(也可以用于更新),put 用来更新,delete 用来删除.

  7. C#读取Mysql blob字段 (转帖)

    http://blog.csdn.net/config_man/article/details/6123191 开发环境:Windows XP Professional SP3.VS2008.Winf ...

  8. 【python】实例-把两个无规则的序列连接成一个序列,并删除重复的元素,新序列按照升序排序

    list_one=[3,6,2,17,7,33,11,7] list_two=[1,2,3,7,4,2,17,33,11] list_new=list_one+list_two list=[] i=0 ...

  9. SpringCloud使用jpa之Rest方式

    这个与上一篇的基本相同,需要修改的只有Dao层的文件: TablesDao.java package com.shinho.dao; import org.springframework.data.j ...

  10. setting.xml配置文件 --转载

    转载出处:http://www.cnblogs.com/yakov/archive/2011/11/26/maven2_settings.html 在此,简单的说下 setting.xml 和 pom ...