#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |