标签:测试数据 区别 正整数 测试 UNC for cstring str color
在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。
Input
Output
Sample Input
2 1
#.
.#
4 4
...#
..#.
.#..
#...
-1 -1
Sample Output
2 1
隔行放棋子的情况没有考虑导致出错
dfs里面放set导致T
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#include <xfunctional>
using namespace std;
int dir[4][2] = { { 0,1 },{ 0,-1 },{ -1,0 },{ 1,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979;
#define ll long long;
#define PII pair<int, int>;
const int mod = 1e9 + 7;
const int marown = 1000 + 5;
int res = 0, n, k, cnt;
vector<string> v;
bool visited[10] = {false};
void dfs(int row)
{
if (cnt == k)
{
res++;
return;
}
if (row >= n)
{
return;
}
for (int i = 0; i < n; i++)
{
if (visited[i]==false && v[row][i] == ‘#‘)
{
cnt++;
visited[i] = true;
dfs(row + 1);
visited[i] = false;
cnt--;
}
}
dfs(row + 1);
}
int main()
{
while (cin >> n >> k && n != -1 && k != -1)
{
res = 0;
v.resize(n + 1);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
dfs(0);
cout << res << endl;
}
return 0;
}
标签:测试数据 区别 正整数 测试 UNC for cstring str color
原文地址:https://www.cnblogs.com/dealer/p/12539778.html