lzy20091001 @ 2023-07-17 09:51:27
记录详情
前4个点都是对的,后4个点WA。下载了第5个测试点的数据,n=10时正确的解法总数为724,我的程序算出来却是720,但前三个解是对的。
#include <iostream>
using namespace std;
bool vis1[14], vis2[14], vis3[14];
int a[14], n, ans;
void dfs(int dep)
{
if (dep > n)
{
ans++;
if (ans <= 3)
{
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << "\n";
}
}
else
for (int i = 1; i <= n; i++)
if (!vis1[i] && !vis2[dep - i + n] && !vis3[dep + i])
{
a[dep] = i;
vis1[i] = vis2[dep - i + n] = vis3[dep + i] = true;
dfs(dep + 1);
vis1[i] = vis2[dep - i + n] = vis3[dep + i] = false;
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
dfs(1);
cout << ans << "\n";
return 0;
}
by huihuihuihui @ 2023-07-17 10:33:20
数组开小了
by lzy20091001 @ 2023-07-18 09:14:30
@huihuihuihui 非常感谢!