# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297036 | arnold518 | Skyscraper (JOI16_skyscraper) | C++14 | 975 ms | 400560 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;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 14;
const ll MOD = 1e9+7;
int N, L, A[MAXN+10];
ll dp[(1<<MAXN)][MAXN][110];
ll solve(int mask, int bef, int sum)
{
if(sum>L) return 0;
if(mask==((1<<N)-1)) return 1;
ll &ret=dp[mask][bef][sum];
if(ret!=-1) return ret;
ret=0;
for(int i=0; i<N; i++)
{
if(mask&(1<<i)) continue;
ret+=solve(mask|(1<<i), i, sum+abs(A[i]-A[bef]));
ret%=MOD;
}
return ret;
}
int main()
{
scanf("%d%d", &N, &L);
for(int i=0; i<N; i++) scanf("%d", &A[i]);
memset(dp, -1, sizeof(dp));
ll ans=0;
for(int i=0; i<N; i++) ans=(ans+solve((1<<i), i, 0))%MOD;
printf("%lld\n", ans);
}
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... |