题目链接

http://poj.org/problem?id=1321

思路

和N皇后问题类似

但是有一点不同的是 这个是只需要摆放K个棋子就可以了

所以 我们要做好 两个出口

并且要持续往下一层找

AC代码

#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits> #define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss; const double PI = acos(-1);
const double E = exp(1);
const double eps = 1e-30; const int INF = 0x3f3f3f3f;
const int maxn = 5e4 + 5;
const int MOD = 1e9 + 7; string G[10]; int ans; int n, k, m; int v[10]; void dfs(int cur)
{
if (m == k)
{
ans++;
return;
}
if (cur >= n)
return;
for (int i = 0; i < n; i++)
{
if (G[cur][i] == '#' && v[i] == 0)
{
v[i] = 1;
m++;
dfs(cur + 1);
m--;
v[i] = 0;
}
}
dfs(cur + 1);
} void init()
{
CLR(v);
ans = 0;
} int main()
{
while (scanf("%d%d", &n, &k))
{
if (n == -1 && k == -1)
break;
for (int i = 0; i < n; i++)
cin >> G[i];
init();
m = 0;
dfs(0);
cout << ans << endl;
}
}

最新文章

  1. IE7 浏览器下面设置text-indent属性变成margin属性BUG
  2. opendaylight的Beryllium安装
  3. timus_1007_代码字
  4. 【BZOJ 4455】【UOJ #185】【ZJOI 2016】小星星
  5. HDU 3496 (二维费用的01背包) Watch The Movie
  6. sping配置文件中引入properties文件方式
  7. IPython,让Python显得友好十倍的外套——windows XP/Win7安装详解
  8. 【27前端】字体图标 Font Face
  9. HTML5 前端框架和开发工具【下篇】
  10. linux下使用autoconf制作Makefile
  11. Apache 的常见问题
  12. 面试陷阱1:Integer类型的比较
  13. IO复用
  14. 基于promtheus的监控解决方案
  15. git 无法提交空目录
  16. js类型判断的方法
  17. 【洛谷】4917:天守阁的地板【欧拉函数的应用】【lcm与gcd】【同除根号优化】
  18. Unity3D笔记四 基础知识概念
  19. Docker下使用daocloud镜像加速(基于Centos6)
  20. jquery attr与prop的区别与联系

热门文章

  1. 自学MVC看这里——全网最全ASP.NET MVC 教程汇总【转】
  2. 利用iptables的NAT代理实现内网访问外网
  3. 【前端阅读】——《程序员思维修炼》摘记&amp;读后感&amp;思维导图
  4. 2016.10.17 yaml文件里的labels和Pod、RC、Service的对应关系
  5. 公司的mysql-installer-community-5.7.19.0安装注意
  6. TCP/IP详解 卷一(第四、五章 ARP、RARP)
  7. Nook 2 Root
  8. hdu5386(暴力)
  9. 用Putty连接Linux
  10. Lua学习七----------Lua函数