//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'
const int MOD = int(1e9) + 7;
int n , k;
vector<int> a;
int dp[(1 << 14)][15][100];
void Add(int &e , int b){
e += b;
if(e > MOD) e -= MOD;
if(e < 0) e += MOD;
}
int Mul(int a , int b){
return (1ll * a * b) % MOD;
}
int Pow(int a , int b){
int res = 1;
while(b){
if((b & 1)) res = Mul(res , a);
a = Mul(a , a) , b >>= 1;
}
return res;
}
void f(){
for(int msk = 0 ; msk < (1 << 14) ; msk++){
if(msk == 0){
for(int bit = 0 ; bit < n ; bit++){
dp[msk | (1 << bit)][bit + 1][0] = 1;
}
continue;
}
for(int bit0 = 0 ; bit0 < n ; bit0++){
if(((msk >> bit0) & 1)) continue;
for(int bit1 = 0 ; bit1 < n ; bit1++){
if(!((msk >> bit1) & 1)) continue;
for(int sm = 0 ; sm < k ; sm++){
if(sm + abs(a[bit0] - a[bit1]) > k) continue;
Add(dp[msk | (1 << bit0)][bit0 + 1][sm + abs(a[bit0] - a[bit1])] , dp[msk][bit1 + 1][sm]);
}
}
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 0 ; i < n ; i++){
int d;
cin >> d;
a.pb(d);
}
f();
int o = 0;
for(int end = 1 ; end <= n ; end++){
for(int sm = 0 ; sm <= k ; sm++){
Add(o , dp[(1 << n) - 1][end][sm]);
}
}
cout << o;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
18704 KB |
Output is correct |
3 |
Correct |
17 ms |
38184 KB |
Output is correct |
4 |
Correct |
55 ms |
82000 KB |
Output is correct |
5 |
Incorrect |
347 ms |
93704 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
121 ms |
96220 KB |
Output is correct |
2 |
Correct |
171 ms |
96476 KB |
Output is correct |
3 |
Correct |
118 ms |
96524 KB |
Output is correct |
4 |
Correct |
172 ms |
96596 KB |
Output is correct |
5 |
Correct |
171 ms |
96536 KB |
Output is correct |
6 |
Correct |
176 ms |
96504 KB |
Output is correct |
7 |
Correct |
93 ms |
96340 KB |
Output is correct |
8 |
Correct |
112 ms |
96336 KB |
Output is correct |
9 |
Correct |
151 ms |
96592 KB |
Output is correct |
10 |
Correct |
154 ms |
96592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
18704 KB |
Output is correct |
3 |
Correct |
17 ms |
38184 KB |
Output is correct |
4 |
Correct |
55 ms |
82000 KB |
Output is correct |
5 |
Incorrect |
347 ms |
93704 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |