#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][N+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 |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
1024 KB |
Output is correct |
13 |
Correct |
2 ms |
1024 KB |
Output is correct |
14 |
Correct |
2 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
1024 KB |
Output is correct |
16 |
Correct |
2 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
1024 KB |
Output is correct |
13 |
Correct |
2 ms |
1024 KB |
Output is correct |
14 |
Correct |
2 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
1024 KB |
Output is correct |
16 |
Correct |
2 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
13 ms |
7168 KB |
Output is correct |
22 |
Correct |
13 ms |
7168 KB |
Output is correct |
23 |
Correct |
13 ms |
7168 KB |
Output is correct |
24 |
Correct |
13 ms |
7168 KB |
Output is correct |
25 |
Correct |
13 ms |
7168 KB |
Output is correct |
26 |
Correct |
13 ms |
7168 KB |
Output is correct |
27 |
Correct |
13 ms |
7196 KB |
Output is correct |
28 |
Correct |
5 ms |
3072 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
13 ms |
7168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
288 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
1024 KB |
Output is correct |
13 |
Correct |
2 ms |
1024 KB |
Output is correct |
14 |
Correct |
2 ms |
1024 KB |
Output is correct |
15 |
Correct |
2 ms |
1024 KB |
Output is correct |
16 |
Correct |
2 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
768 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
13 ms |
7168 KB |
Output is correct |
22 |
Correct |
13 ms |
7168 KB |
Output is correct |
23 |
Correct |
13 ms |
7168 KB |
Output is correct |
24 |
Correct |
13 ms |
7168 KB |
Output is correct |
25 |
Correct |
13 ms |
7168 KB |
Output is correct |
26 |
Correct |
13 ms |
7168 KB |
Output is correct |
27 |
Correct |
13 ms |
7196 KB |
Output is correct |
28 |
Correct |
5 ms |
3072 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
13 ms |
7168 KB |
Output is correct |
31 |
Runtime error |
1 ms |
384 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |