제출 #415280

#제출 시각아이디문제언어결과실행 시간메모리
415280errorgornSkyscraper (JOI16_skyscraper)C++17
15 / 100
70 ms130528 KiB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=1000000007;

int n,m;
int arr[105];
int memo[105][105][1005][3];

ll dp(int i,int j,int k,int l){
	//processed, num connected, cost, sides
	if (k>m) return 0;
	if (i==n){
		if (j==1 && l==0) return 1;
		else return 0;
	}
	if (memo[i][j][k][l]!=-1) return memo[i][j][k][l];
	
	ll res=0;
	
	//put on a endpoint and touch connected
	if (l && j){
		res=(res+dp(i+1,j,k+(2*j-2+(l-1))*arr[i],l-1)*l)%MOD;
	}
	
	//put on endpoint and dont touch
	if (l){
		res=(res+dp(i+1,j+1,k+(2*j+(l-1))*arr[i],l-1)*l)%MOD;
	}
	
	//touch connected
	if (j){
		res=(res+dp(i+1,j,k+(2*j-2+l)*arr[i],l)*(2*(j-1)+l))%MOD;
	}
	
	//touch nothing
	res=(res+dp(i+1,j+1,k+(2*j+l)*arr[i],l)*(j-1+l))%MOD;
	
	//join 2 connected
	if (j>1){
		res=(res+dp(i+1,j-1,k+(2*j-4+l)*arr[i],l)*(j-1))%MOD;
	}
	
	//cout<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<res<<endl;
	return memo[i][j][k][l]=res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>m;
	rep(x,0,n) cin>>arr[x];
	sort(arr,arr+n);
	
	rep(x,0,n) arr[x]=arr[x+1]-arr[x];
	//rep(x,0,n-1) cout<<arr[x]<<" "; cout<<endl;
	
	memset(memo,-1,sizeof(memo));
	cout<<dp(0,0,0,2)<<endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...