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>
using namespace std;
#define int long long
const int mod = 1e9 +7;
const int MAX_N = 350;
int n, nb_c[MAX_N][MAX_N+1], dp[MAX_N][MAX_N+1];
int C[MAX_N+1][MAX_N];
int expo(int a, int b){
if(b==0){
return 1;
}
if(b%2==1){
return (a*expo(a, b-1))%mod;
}
else{
return (expo(a, b/2)*expo(a, b/2))%mod;
}
}
signed main(){
cin>>n;
C[0][0] =1;
C[1][0] = 1;
C[1][1] = 1;
for(int i = 2; i<=n; i++){
for(int j =0; j<=n; j++){
C[i][j] = C[i-1][j];
if(j>0){
C[i][j] = (C[i][j]+ C[i-1][j-1])%mod;
}
}
cout<<endl;
}
for(int i = n-1; i>=0; i--){
for(int j = 0; j<=n; j++){
nb_c[i][j] = expo((n-i), j);
}
}
for(int i = n-1; i>=0; i--){
for(int j = 0; j<=n; j++){
int cost = i+1;
if(i==n-1){
if(j==cost){
dp[i][j] = 1;
}
else{
dp[i][j] = 0;
}
}
else{
for(int k = 0; k<=j; k++){
if(k!=cost){
dp[i][j] = (dp[i][j]+ (dp[i+1][j-k] * C[j][k])%mod)%mod;
}
}
if(j>=cost){
dp[i][j] = (dp[i][j]+ (nb_c[i+1][j-cost] * C[j][cost])%mod)%mod;
}
}
}
}
cout<<dp[0][n]<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |