站外题WA,样例都不对(玄3关)
  • 板块灌水区
  • 楼主Wendy_Hello_qwq
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/5/19 11:36
  • 上次更新2024/5/19 14:11:25
查看原帖
站外题WA,样例都不对(玄3关)
1039211
Wendy_Hello_qwq楼主2024/5/19 11:36

题目传送门

代码:

#include <bits/stdc++.h>
using namespace std;
int n, k, ans;
char s[17][17];
int a[17], b[17];
void dfs (int, int);
int main()
{
	while (cin >> n >> k)
	{
		ans = 0;
		memset (a, 0, sizeof (a));
		memset (b, 0, sizeof (b));
		if (n == -1 && k == -1)
			break;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= n; j++)
				cin >> s[i][j];
		}
		dfs (1, 1);
		printf ("%d\n", ans);
	}
	return 0;
}
void dfs (int x, int y)
{
	if (y > k)
	{
		ans++;
		return;
	}
	if (x > n)
		return;
	else
	{
		if (a[x] == 0 && b[y]  == 0 && s[x][y] == '#')
		{
			a[x] = 1;
			b[y] = 1;
			dfs (x,  y + 1);
			a[x] = 0;
			b[y] = 0;
		}
		dfs (x + (y + 1) / n, (y + 1) % n);
	}
}
2024/5/19 11:36
加载中...