#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e5 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 480;
ll gt[N];
ll n,m;
ll bpow(ll a, ll b){
if(b == 0) return 1;
ll res = bpow(a , b/2);
if(b&1) return a * res % mod * res % mod;
return res * res % mod;
}
ll C(ll k, ll n){
if(k > n || min(n, k) < 0) return 0;
ll a = gt[n], b = gt[n - k] * gt[k] % mod;
return a * bpow(b, mod - 2) % mod;
}
const int MAXN = 3010;
ll dp[MAXN][MAXN] , p[MAXN][MAXN];
void to_thic_cau(){
cin >> n >> m;
ll res = 0;
for(int i = 0 ; i <= max(n , m) ; i++){
for(int j = 0; j <= i ; j++){
if(i == 0 or j == 0) dp[j][i] = 1;
else{
dp[j][i] = (dp[j-1][i] + i * dp[j-1][i-1]* 4 % mod) % mod;
}
}
}
for(int i = 0; i <= max(m, n);i++){
p[i][0] = 1;
for(int j = 1; j <= i;j++){
p[i][j] = (p[i][j-1] * C(2, i - 2 * (j - 1))) % mod;
}
}
for(int i = 0; i <= n;i++){ // fix i hang dung 2 con -> con m - 2 * i cot
for(int j = 0; j <= m;j++){
if(n - i < 0) continue;
ll pi = p[m][i], pj = p[n - i][j];
//for(int k = 1; k <= i;k++) pi = (pi * C(2, m - 2 * (k - 1))) % mod;
//for(int k = 1; k <= j;k++) pj = (pj * C(2, n - i - 2 * (k - 1))) % mod;
ll x = n - 2 * j - i, y = m - 2 * i - j;
if(x < 0 || y < 0) continue;
ll d = dp[min(x , y)][max(x, y)];
res = (res + ((C(i, n) * pi % mod) * (C(j, m - 2 * i) * pj % mod) % mod) * d % mod) % mod;
}
}
cout << (res + mod - 1) % mod << '\n';
}
signed main(){
gt[0] = 1;
for(int i = 1; i < N;i++) {
gt[i] = (gt[i-1] * i) % mod;
}
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}//beo
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2136 KB |
Output is correct |
2 |
Correct |
4 ms |
3672 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
3932 KB |
Output is correct |
5 |
Correct |
6 ms |
4440 KB |
Output is correct |
6 |
Correct |
6 ms |
4188 KB |
Output is correct |
7 |
Correct |
6 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4448 KB |
Output is correct |
9 |
Correct |
3 ms |
2904 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
8 ms |
5088 KB |
Output is correct |
12 |
Correct |
14 ms |
4952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2136 KB |
Output is correct |
2 |
Correct |
4 ms |
3672 KB |
Output is correct |
3 |
Correct |
2 ms |
2396 KB |
Output is correct |
4 |
Correct |
5 ms |
3932 KB |
Output is correct |
5 |
Correct |
6 ms |
4440 KB |
Output is correct |
6 |
Correct |
6 ms |
4188 KB |
Output is correct |
7 |
Correct |
6 ms |
4188 KB |
Output is correct |
8 |
Correct |
7 ms |
4448 KB |
Output is correct |
9 |
Correct |
3 ms |
2904 KB |
Output is correct |
10 |
Correct |
10 ms |
4956 KB |
Output is correct |
11 |
Correct |
8 ms |
5088 KB |
Output is correct |
12 |
Correct |
14 ms |
4952 KB |
Output is correct |
13 |
Correct |
207 ms |
43088 KB |
Output is correct |
14 |
Correct |
333 ms |
61960 KB |
Output is correct |
15 |
Correct |
851 ms |
83540 KB |
Output is correct |
16 |
Correct |
153 ms |
33376 KB |
Output is correct |
17 |
Correct |
252 ms |
41808 KB |
Output is correct |
18 |
Correct |
225 ms |
26852 KB |
Output is correct |
19 |
Correct |
976 ms |
90416 KB |
Output is correct |
20 |
Correct |
751 ms |
68580 KB |
Output is correct |
21 |
Correct |
513 ms |
52332 KB |
Output is correct |
22 |
Correct |
531 ms |
55852 KB |
Output is correct |
23 |
Correct |
600 ms |
94508 KB |
Output is correct |
24 |
Correct |
1224 ms |
94656 KB |
Output is correct |
25 |
Correct |
923 ms |
75344 KB |
Output is correct |
26 |
Correct |
976 ms |
85884 KB |
Output is correct |
27 |
Correct |
1101 ms |
92712 KB |
Output is correct |