#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0)
#define fori(x,a,b) for (int x=a;x<=b;++x)
#define ford(x,a,b) for (int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define mp make_pair
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);
/*
f[i][j] : so cach tao ra cac nhom thoa man khi xet den i-1 ptu dau tien va con j nhom loai 1;
- loai 1 : gt con dau < gt con thu 2,gt con cuoi < gt con ke no
- loai 2 : bat dau la cs(tuong tu loai 1 nhung bat dau co 2 cach)
- loai 3 : ket thuc la cf(tuong tu loai 1 nhung ket thuc co 2 cach)
*/
const int mod = 1e9 + 7;
const int N = 2e3 + 5;
int f[N][N],n,cs,cf;
void add(int &a,int b)
{
a+=b;
if(a>=mod) a-=mod;
}
main()
{
fasty;
cin>>n>>cs>>cf;
if(cs>cf) swap(cs,cf);
f[1][0] = 1;
fori(i,1,n) fori(j,0,i-1) if(f[i][j])
{
if(i==cf || i==cs)
{
add(f[i+1][j],f[i][j]);//ghep cs(cf) voi i+1 thanh nhom loai 1
if(j) add(f[i+1][j-1],f[i][j]*j%mod);//ghep cs(cf) voi con nho hon no
}
else
{
if(j>1) add(f[i+1][j-1],f[i][j]*j%mod*(j-1)%mod); //gop 2 nhom loai 1;
add(f[i+1][j+1],f[i][j]);//i thanh 1 nhom rieng;
if(cs<i) add(f[i+1][j-1],f[i][j]*j%mod);//gop nhom 2 voi nhom 1 THANH 1 NHOM 2
if(cf<i) add(f[i+1][j-1],f[i][j]*j%mod);//gop nhom 1 voi nhom 3 THANH 1 NHOM 3
}
}
cout<<f[n][0];
}
Compilation message
kangaroo.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
452 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
452 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
2 ms |
1228 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
16 |
Correct |
2 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1220 KB |
Output is correct |
20 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
452 KB |
Output is correct |
9 |
Correct |
4 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
456 KB |
Output is correct |
12 |
Correct |
2 ms |
1228 KB |
Output is correct |
13 |
Correct |
2 ms |
1100 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1228 KB |
Output is correct |
16 |
Correct |
2 ms |
1228 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
2 ms |
1220 KB |
Output is correct |
20 |
Correct |
2 ms |
1228 KB |
Output is correct |
21 |
Correct |
7 ms |
4580 KB |
Output is correct |
22 |
Correct |
8 ms |
5068 KB |
Output is correct |
23 |
Correct |
11 ms |
5552 KB |
Output is correct |
24 |
Correct |
59 ms |
23048 KB |
Output is correct |
25 |
Correct |
47 ms |
22880 KB |
Output is correct |
26 |
Correct |
50 ms |
22980 KB |
Output is correct |
27 |
Correct |
52 ms |
22772 KB |
Output is correct |
28 |
Correct |
35 ms |
15076 KB |
Output is correct |