#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;
const ll Mod = 1e9 + 7;
int n, l;
int a[1010];
ll dp[17000][14][1111];
int main() {
fast;
cin >> n >> l;
for(int i=0; i<n; i++) {
cin >> a[i];
}
for(int i=1; i<(1<<n); i++) {
if(__builtin_popcount(i) == 1) {
for(int j=0; j<n; j++) {
if(i == (1<<j)) {
dp[i][j][0] = 1;
}
}
continue;
}
for(int j=0; j<n; j++) {
if(~i & (1<<j)) continue;
for(int k=0; k<=l; k++) {
for(int m=0; m<n; m++) {
if(m == j) continue;
if(~i & (1<<m)) continue;
if(abs(a[m] - a[j]) > k) continue;
dp[i][j][k] += dp[i ^ (1<<j)][m][k - abs(a[m] - a[j])];
dp[i][j][k] %= Mod;
}
}
}
}
ll ans = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<=l; j++) {
ans += dp[(1<<n)-1][i][j];
ans %= Mod;
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
1280 KB |
Output is correct |
5 |
Correct |
28 ms |
9848 KB |
Output is correct |
6 |
Correct |
25 ms |
9592 KB |
Output is correct |
7 |
Correct |
8 ms |
5504 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
27 ms |
9856 KB |
Output is correct |
10 |
Correct |
7 ms |
5376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
111480 KB |
Output is correct |
2 |
Runtime error |
890 ms |
524292 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
1280 KB |
Output is correct |
5 |
Correct |
28 ms |
9848 KB |
Output is correct |
6 |
Correct |
25 ms |
9592 KB |
Output is correct |
7 |
Correct |
8 ms |
5504 KB |
Output is correct |
8 |
Correct |
6 ms |
5120 KB |
Output is correct |
9 |
Correct |
27 ms |
9856 KB |
Output is correct |
10 |
Correct |
7 ms |
5376 KB |
Output is correct |
11 |
Correct |
148 ms |
111480 KB |
Output is correct |
12 |
Runtime error |
890 ms |
524292 KB |
Execution killed with signal 9 |
13 |
Halted |
0 ms |
0 KB |
- |