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 all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
const ll MOD=1000000007LL;
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);}
int main(){
ll n,k;cin>>n>>k;if(n>3000)return 0;
vector<vector<ll>> dp(n+10,vector<ll>(n+10));
dp[0][0]=1;
for(ll i=1;i<=n;i++){
for(ll j=0;j<i;j++){//i+1通り挿入できる
dp[i][j]+=dp[i-1][j]*(j+1LL)%MOD;
if(j>0){
dp[i][j]+=dp[i-1][j-1]*(i-j)%MOD;
}
dp[i][j]%=MOD;
}
}
cout<<dp[n][k-1]<<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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |