This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;
ll n,dp[350][350],mod=7+1e9,C[350][350];
bool use[350][350];
ll coeff(ll N,ll K){
if( K==0 || K==N ) return 1;
if( C[N][K] ) return C[N][K];
return C[N][K] = (coeff( N-1 , K-1 ) + coeff( N-1 , K ) )%mod;
}
ll expBin( ll A , ll B ){
if( !B ) return 1LL;
ll myAns = expBin( A , B/2 );
myAns = (myAns*myAns)%mod;
if( B&1 ) myAns = (myAns*A)%mod;
return myAns;
}
ll fn( ll pos , ll T ){
if( !pos || !T ) return 0LL;
if( use[pos][T] ) return dp[pos][T];
use[pos][T] = true;
ll myAns = 0LL;
if( pos <= T ){
myAns = ( coeff( T , pos )*expBin( pos-1 , T-pos ) )%mod;
}
for(ll i=0; i<=T; i++){
if( i==pos ) continue;
myAns = ( myAns + ((coeff( T , i )*fn( pos-1 , T-i ))%mod) )%mod;
}
return dp[pos][T] = myAns;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << fn( n , n );
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |