# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
132867 | tushar_2658 | Skyscraper (JOI16_skyscraper) | C++14 | 1294 ms | 196544 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 105;
int a[maxn];
long long dp[1 << 15][15][105];
int n, m;
long long mod = 1e9 + 7;
int main(int argc, char const *argv[])
{
// freopen("in.txt", "r", stdin);
scanf("%d %d", &n, &m);
for(int i=0; i<n; i++){
scanf("%d", &a[i]);
}
for(int i=0; i<n; i++){
dp[1 << i][i][0] = 1;
}
for(int mask = 0; mask < (1 << n); mask++){
for(int j=0; j<n; j++){
if((mask >> j)&1){
for(int k=0; k <= m; k++){
for(int l=0; l<n; l++){
if((mask >> l)&1){}
else {
if(k + abs(a[l] - a[j]) <= m){
dp[mask | (1 << l)][l][k + abs(a[l] - a[j])] =(dp[mask][j][k] + dp[mask | (1 << l)][l][k + abs(a[l] - a[j])])%mod;
}
}
}
}
}
}
}
int ans = 0;
for(int i=0; i<n; i++){
for(int j=0; j<m+1; j++){
ans += dp[(1 << n)-1][i][j];
ans %= mod;
}
}cout << ans <<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |