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;
typedef long long ll;
const int MOD = 1e9+7;
const int mx = 3005;
struct mi{
ll v;
mi(){
v = 0;
}
mi(ll _v){
v = _v % MOD;
}
};
mi& operator+=(mi& a, mi b){
a.v+=b.v;
if(a.v >= MOD) a.v-=MOD;
return a;
}
mi operator+(mi a, mi b){
a+=b;
return a;
}
mi operator*(mi a, mi b){
a.v = (a.v*b.v) % MOD;
return a;
}
mi dp[mx][mx];
int main(){
int N, K;
cin >> N >> K;
dp[0][0] = mi(1);
for(int i = 0; i <= N+2; i++){
for(int j = 0; j <= N+2; j++){
dp[i][j+1]+=mi(i+1)*dp[i][j];
dp[i+1][j]+=mi(j+1)*dp[i][j];
}
}
cout << dp[N-K][K-1].v << "\n";
}
# | 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... |