# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
51146 | 2018-06-16T23:30:11 Z | spencercompton | Skyscraper (JOI16_skyscraper) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; // ll dp[14][1001][1<<14]; vector<vector<vector<ll> > > > dp; int n, l; int ar[100]; ll mod = 1000000007LL; ll go(int mask, int rem, int last){ if(rem<0){ return 0LL; } if(mask==0){ return 1LL; } if(dp[last][rem][mask]!=-1LL){ return dp[last][rem][mask]; } ll ret = 0LL; for(int i = 0; i<n; i++){ if((mask&(1<<i))!=0){ ret += go(mask-(1<<i), rem-abs(ar[i]-ar[last]),i); } } ret %= mod; dp[last][rem][mask] = ret; return ret; } int main(){ cin >> n >> l; for(int i = 0; i<n; i++){ cin >> ar[i]; } int maxi = (1<<n); for(int i = 0; i<n; i++){ vector<vector<ll> > a; for(int j = 0; j<=l; j++){ vector<ll> b; for(int k = 0; k<maxi; k++){ b.push_back(-1LL); } a.push_back(b); } dp.push_back(a); } ll ret = 0; for(int i = 0; i<n; i++){ ret += go(maxi-1-(1<<i), l, i); } ret %= mod; cout << ret << endl; }