mirror of
https://github.com/wczffl-503/OI-Codes.git
synced 2025-07-07 18:06:58 +08:00
Upload via code
This commit is contained in:
56
FZOI/四色问题.cpp
Normal file
56
FZOI/四色问题.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
const int MAXN = 8;
|
||||
int n;
|
||||
int arr[MAXN][MAXN];
|
||||
int color[MAXN];
|
||||
int ans;
|
||||
|
||||
bool f(int v, int c)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (arr[v][i] && color[i] == c)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void dfs(int v)
|
||||
{
|
||||
if (v == n)
|
||||
{
|
||||
ans++;
|
||||
return;
|
||||
}
|
||||
for (int c = 1; c <= 4; c++)
|
||||
{
|
||||
if (f(v, c))
|
||||
{
|
||||
color[v] = c;
|
||||
dfs(v + 1);
|
||||
color[v] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
for (int j = 0; j < n; j++)
|
||||
{
|
||||
cin >> arr[i][j];
|
||||
}
|
||||
}
|
||||
memset(color, 0, sizeof(color));
|
||||
ans = 0;
|
||||
dfs(0);
|
||||
cout << ans << endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user