-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathP2915.c
More file actions
33 lines (30 loc) · 881 Bytes
/
P2915.c
File metadata and controls
33 lines (30 loc) · 881 Bytes
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
#include "stdio.h"
#include "stdlib.h"
#define maxn 16
typedef long long LL;
LL dp[maxn][1 << maxn];
LL s[maxn];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++)
scanf("%lld", s + i);
for (int i = 0; i < n; i++)
dp[i][1 << (n - i - 1)] = 1;
int new_state;
for (int state = 1; state < (1 << n); state++)
for (int i = 0; i < n; i++) {
if (state & (1 << (n - i - 1))) continue;
new_state = state | (1 << (n - i - 1));
for (int j = 0; j < n; j++) {
if (!(state & (1 << (n - j - 1)))) continue;
if (abs(s[i] - s[j]) <= k) continue;
dp[i][new_state] += dp[j][state];
}
}
LL result = 0;
for (int i = 0; i < n; i++)
result += dp[i][(1 << n) - 1];
printf ("%lld", result);
return 0;
}