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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//4 pts: N <= 10
/*
int main()
{
int N, K;
cin >> N >> K;
vector<int> X(N);
for(int i = 1; i <= N; i++) X[i-1] = i;
int res = 0;
int a;
do
{
a = 1;
for(int i = 1; i < N; i++) if(X[i-1] > X[i]) a++;
if(a == K) res++;
} while(next_permutation(X.begin(), X.end()));
cout << res << '\n';
return 0;
}
*/
/*
dp[i][j]
Order has sentences 1..i and can be read in j days
Sentence number i+1 can be inserted anywhere but the end of a day to create a new day.
i.e. dp[i+1][j] += dp[i][j] * j;
dp[i+1][j+1] += dp[i][j] * (i - j + 1);
*/
long long mod = 1e9+7;
//20 pts: N <= 300
int main()
{
long long N, K;
cin >> N >> K;
long long dp[N+1][K+1];
dp[1][1] = 1;
for(long long i = 2; i <= N; i++)
{
dp[i][1] = 1;
for(long long j = 2; j < i; j++)
{
dp[i][j] = ((dp[i-1][j] * j) % mod + (dp[i-1][j-1] * (i - j + 1)) % mod) % mod;
}
dp[i][i] = 1;
}
cout << dp[N][K] << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |