Submission #31362

#TimeUsernameProblemLanguageResultExecution timeMemory
31362tatatanSkyscraper (JOI16_skyscraper)C++11
100 / 100
693 ms174612 KiB
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define pii pair<int,int> #define LL long long #define st first #define nd second #define endl '\n' using namespace std; int n,L,dp[105][105][2][2][1001],a[105],mod=1e9+7; void add(int &x,LL y) { y%=mod; x+=y; if(x>=mod) x-=mod; } int f(int x,int cnt,int l,int r,int sum) { if(x>0) sum+=(cnt*2+l+r)*(a[x]-a[x-1]); if(sum>L||cnt<0) return 0; if(x==n-1) return (cnt==0); int &ret=dp[x][cnt][l][r][sum]; if(ret!=-1) return ret; ret=0; add(ret,f(x+1,cnt,1,r,sum)); add(ret,1LL*f(x+1,cnt-1,1,r,sum)*cnt); add(ret,f(x+1,cnt,l,1,sum)); add(ret,1LL*f(x+1,cnt-1,l,1,sum)*cnt); add(ret,f(x+1,cnt+1,l,r,sum)); add(ret,1LL*f(x+1,cnt,l,r,sum)*cnt*2); add(ret,1LL*f(x+1,cnt-1,l,r,sum)*cnt*(cnt-1)); return ret; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); memset(dp,-1,sizeof dp); cin>>n>>L; for(int i=0;i<n;++i) cin>>a[i]; sort(a,a+n); cout<<f(0,0,0,0,0)<< endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...