This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
const int md = 1e9+7;
void add(int &a, int b)
{
a += b;
if(a>= md) a-= md;
}
int mul(int a, int b)
{
return (1LL*a*b)%md;
}
const int maxn = 3e3+5;
int dp[maxn][maxn];
int main()
{
int n, k;
cin >> n >> k;
dp[1][0] = 1;
for(int i = 2; i<= n; i++)
{
for(int j = 0; j< i; j++)
{
dp[i][j] = mul(j+1, dp[i-1][j]);
add(dp[i][j], mul(i-j, dp[i-1][j-1]));
//printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
}
}
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... |