# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
51146 | spencercompton | Skyscraper (JOI16_skyscraper) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}