-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
34 lines (32 loc) · 856 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections.Generic;
namespace BeautifulArrangement
{
class Program
{
static void Main(string[] args)
{
int n = 3;
Console.WriteLine(CountArrangement(n));
}
static int CountArrangement(int n)
{
var res = 0;
DFS(n, 1, new bool[n + 1], ref res);
return res;
}
static void DFS(int n, int count, bool[] visited, ref int res)
{
if (count == n + 1) res++;
for (int i = 1; i <= n; i++)
{
if (!visited[i] && (i % count == 0 || count % i == 0))
{
visited[i] = true;
DFS(n, count + 1, visited, ref res);
visited[i] = false;
}
}
}
}
}