Submission #51145

# Submission time Handle Problem Language Result Execution time Memory
51145 2018-06-16T23:28:10 Z spencercompton Skyscraper (JOI16_skyscraper) C++17
0 / 100
1 ms 224 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[14][1001][1<<14];
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++){
		for(int j = 0; j<=l; j++){
			for(int k = 0; k<maxi; k++){
				dp[i][j][k] = -1LL;
			}
		}
	}
	ll ret = 0;
	for(int i = 0; i<n; i++){
		ret += go(maxi-1-(1<<i), l, i);
	}
	ret %= mod;
	cout << ret << endl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 128 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 224 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 128 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -