Submission #704072

#TimeUsernameProblemLanguageResultExecution timeMemory
704072PacybwoahMagneti (COCI21_magneti)C++14
110 / 110
201 ms208456 KiB
#include<iostream> #include<vector> #include<algorithm> #define ll long long using namespace std; const ll mod=1e9+7; ll power(ll a,ll b){ if(b==0) return 1; if(b&1) return power(a,b-1)*a%mod; ll tmp=power(a,b/2); return tmp*tmp%mod; } ll inverse(ll a){ return power(a,mod-2); } int main(){ ll n,l; cin>>n>>l; vector<ll> vec(n); vector<ll> fac(20001); fac[0]=1; for(ll i=1;i<=20000;i++) fac[i]=fac[i-1]*i%mod; vector<ll> invfac(20001); for(ll i=0;i<=20000;i++) invfac[i]=inverse(fac[i]); for(int i=0;i<n;i++) cin>>vec[i]; vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(l+1,0))); dp[1][1][0]=1; sort(vec.begin(),vec.end()); for(ll i=2;i<=n;i++){ for(ll j=1;j<=i;j++){ for(ll k=0;k<=l;k++){ if(j+1<=n&&k-2*vec[i-1]>=0) dp[i][j][k]=dp[i-1][j+1][k-2*vec[i-1]]*(j*(j+1)%mod)%mod; if(j-1>=0) dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-1][k])%mod; if(k-vec[i-1]>=0) dp[i][j][k]=(dp[i][j][k]+dp[i-1][j][k-vec[i-1]]*j*2%mod)%mod; } } } ll ans=0; for(int i=0;i<l;i++){ ans=(ans+fac[l-1-i+n]*invfac[n]%mod*invfac[l-1-i]%mod*dp[n][1][i]%mod)%mod; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...