#include <bits/stdc++.h>
#define MAX 2005
using ll = long long;
const ll MOD = 1e9+7;
ll binominal[MAX][MAX];
bool exbin[MAX][MAX];
ll dpbin(int a,int b){
if(!b)return 1;
if(!a)return 0;
if(exbin[a][b])return binominal[a][b];
exbin[a][b]=true;
return binominal[a][b] = (dpbin(a-1,b)+dpbin(a-1,b-1))%MOD;
}
bool existe[MAX][MAX];
ll tab[MAX][MAX];
ll fat[MAX];
std::vector<int> tamanhos;
ll dp(int nunca_pegou,int pegou_uma_vez,int seq){
if(seq==tamanhos.size()){
//std::cout<<"Chegou! "<<nunca_pegou+pegou_uma_vez<<"\n";
if(nunca_pegou+pegou_uma_vez==0)
return 1;
return 0;
}
if(existe[nunca_pegou][pegou_uma_vez])return tab[nunca_pegou][pegou_uma_vez];
existe[nunca_pegou][pegou_uma_vez]=true;
// std::cout<<nunca_pegou<<" "<<pegou_uma_vez<<" "<<seq<<"\n";
int tem_q_pegar = tamanhos[seq];
ll resposta=0;
for(int i=0;i<=std::min(tem_q_pegar,pegou_uma_vez);++i){
int necessita = tem_q_pegar-i;
if(nunca_pegou<necessita)continue;
ll chance1 = dpbin(nunca_pegou,necessita);
ll chance2 = dpbin(pegou_uma_vez,i);
ll total = (chance1*chance2)%MOD;
ll res = dp(nunca_pegou-necessita,pegou_uma_vez-i+necessita,seq+1);
ll totalres = (total*res)%MOD;
ll fatty = fat[tem_q_pegar];
ll truetotral = (fatty*totalres)%MOD;
resposta=(resposta+truetotral)%MOD;
}
return tab[nunca_pegou][pegou_uma_vez]=resposta;
}
int main()
{
// std::cout<<dpbin(10,6)<<"\n";
int N,M;
std::cin>>N>>M;
fat[0]=1;
for(int i=1;i!=MAX;++i)fat[i]=(fat[i-1]*i)%MOD;
{
int x = (2*N)/M;
for(int i=0;i!=M;++i)tamanhos.push_back(x);
for(int i=0;i!=((2*N)%M);++i)tamanhos[i]++;
ll xa=0;
for(int i=0;i!=M;++i){
xa+=tamanhos[i];
//std::cout<<tamanhos[i]<<" \n"[i==M-1];
}
assert(xa==(2*N));
}
ll bonus=1;
for(int i=0;i!=N;++i)bonus=(bonus*2)%MOD;
std::cout<<((dp(N,0,0)*bonus)%MOD)<<"\n";
}
Compilation message
Main.cpp: In function 'll dp(int, int, int)':
Main.cpp:23:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(seq==tamanhos.size()){
| ~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
5 ms |
3796 KB |
Output is correct |
23 |
Correct |
4 ms |
3284 KB |
Output is correct |
24 |
Correct |
3 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
5 ms |
3796 KB |
Output is correct |
23 |
Correct |
4 ms |
3284 KB |
Output is correct |
24 |
Correct |
3 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
4308 KB |
Output is correct |
28 |
Correct |
8 ms |
8892 KB |
Output is correct |
29 |
Correct |
13 ms |
9812 KB |
Output is correct |
30 |
Correct |
11 ms |
9684 KB |
Output is correct |
31 |
Correct |
9 ms |
8988 KB |
Output is correct |
32 |
Correct |
10 ms |
10396 KB |
Output is correct |
33 |
Correct |
13 ms |
10928 KB |
Output is correct |
34 |
Correct |
18 ms |
14320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
1492 KB |
Output is correct |
12 |
Correct |
1 ms |
1108 KB |
Output is correct |
13 |
Correct |
1 ms |
980 KB |
Output is correct |
14 |
Correct |
1 ms |
1108 KB |
Output is correct |
15 |
Correct |
1 ms |
1108 KB |
Output is correct |
16 |
Correct |
1 ms |
1236 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
980 KB |
Output is correct |
20 |
Correct |
3 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
5 ms |
3796 KB |
Output is correct |
23 |
Correct |
4 ms |
3284 KB |
Output is correct |
24 |
Correct |
3 ms |
4180 KB |
Output is correct |
25 |
Correct |
2 ms |
3668 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
3 ms |
4308 KB |
Output is correct |
28 |
Correct |
8 ms |
8892 KB |
Output is correct |
29 |
Correct |
13 ms |
9812 KB |
Output is correct |
30 |
Correct |
11 ms |
9684 KB |
Output is correct |
31 |
Correct |
9 ms |
8988 KB |
Output is correct |
32 |
Correct |
10 ms |
10396 KB |
Output is correct |
33 |
Correct |
13 ms |
10928 KB |
Output is correct |
34 |
Correct |
18 ms |
14320 KB |
Output is correct |
35 |
Correct |
35 ms |
29072 KB |
Output is correct |
36 |
Correct |
68 ms |
33868 KB |
Output is correct |
37 |
Correct |
33 ms |
28620 KB |
Output is correct |
38 |
Correct |
46 ms |
30736 KB |
Output is correct |
39 |
Correct |
67 ms |
29124 KB |
Output is correct |
40 |
Correct |
90 ms |
39132 KB |
Output is correct |