#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;
const int MOD = 1e9 + 7;
int add(int a, int b)
{
a+=b; while(a>=MOD) a-=MOD;
return a;
}
int mult(int a, int b)
{
return (a*1LL*b)%MOD;
}
int C[3111][3111];
int fact[6111];
int pow2[6111];
int ipow2[6111];
int modpow(int a, int b)
{
int r=1;
while(b)
{
if(b&1) r=mult(r,a);
a=mult(a,a); b>>=1;
}
return r;
}
int choose(int a, int b)
{
if(a<b) return 0;
if(b==0) return 1;
if(C[a][b]!=-1) return C[a][b];
return (C[a][b] = add(choose(a-1,b-1), choose(a-1,b)));
}
int dp[3111][3111];
int solve(int a, int b)
{
if(a==0) return 1;
if(a<0||b<0) return 0;
if(dp[a][b]!=-1) return dp[a][b];
return (dp[a][b] = add(solve(a-1,b),add(mult(4*b, solve(a-1,b-1)), mult((b*(b-1))/2, solve(a-1,b-2)))));
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int n,m; cin>>n>>m;
memset(C,-1,sizeof(C)); memset(dp,-1,sizeof(dp));
fact[0]=1; pow2[0]=ipow2[0]=1;
for(int i=1;i<=6001;i++)
{
pow2[i]=add(pow2[i-1],pow2[i-1]);
ipow2[i] = modpow(pow2[i], MOD-2);
}
for(int i=1;i<=6001;i++) fact[i]=mult(fact[i-1],i);
int ans=0;
for(int i=0;i<=m;i++)
{
int coeff = mult(choose(m, i), mult(choose(n, 2*i), mult(fact[2*i], ipow2[i])));
ans = add(ans, mult(coeff, solve(n - 2*i, m - i)));
}
ans=add(ans,MOD-1);
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
76152 KB |
Output is correct |
2 |
Correct |
72 ms |
76340 KB |
Output is correct |
3 |
Correct |
62 ms |
76340 KB |
Output is correct |
4 |
Correct |
60 ms |
76340 KB |
Output is correct |
5 |
Correct |
59 ms |
76340 KB |
Output is correct |
6 |
Correct |
64 ms |
76368 KB |
Output is correct |
7 |
Correct |
71 ms |
76368 KB |
Output is correct |
8 |
Correct |
59 ms |
76368 KB |
Output is correct |
9 |
Correct |
58 ms |
76368 KB |
Output is correct |
10 |
Correct |
60 ms |
76368 KB |
Output is correct |
11 |
Correct |
61 ms |
76368 KB |
Output is correct |
12 |
Correct |
64 ms |
76432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
76152 KB |
Output is correct |
2 |
Correct |
72 ms |
76340 KB |
Output is correct |
3 |
Correct |
62 ms |
76340 KB |
Output is correct |
4 |
Correct |
60 ms |
76340 KB |
Output is correct |
5 |
Correct |
59 ms |
76340 KB |
Output is correct |
6 |
Correct |
64 ms |
76368 KB |
Output is correct |
7 |
Correct |
71 ms |
76368 KB |
Output is correct |
8 |
Correct |
59 ms |
76368 KB |
Output is correct |
9 |
Correct |
58 ms |
76368 KB |
Output is correct |
10 |
Correct |
60 ms |
76368 KB |
Output is correct |
11 |
Correct |
61 ms |
76368 KB |
Output is correct |
12 |
Correct |
64 ms |
76432 KB |
Output is correct |
13 |
Correct |
100 ms |
76512 KB |
Output is correct |
14 |
Correct |
61 ms |
76640 KB |
Output is correct |
15 |
Correct |
317 ms |
76640 KB |
Output is correct |
16 |
Correct |
102 ms |
76640 KB |
Output is correct |
17 |
Correct |
106 ms |
76640 KB |
Output is correct |
18 |
Correct |
110 ms |
76640 KB |
Output is correct |
19 |
Correct |
329 ms |
76640 KB |
Output is correct |
20 |
Correct |
259 ms |
76640 KB |
Output is correct |
21 |
Correct |
180 ms |
76668 KB |
Output is correct |
22 |
Correct |
183 ms |
76668 KB |
Output is correct |
23 |
Correct |
192 ms |
76744 KB |
Output is correct |
24 |
Correct |
390 ms |
76744 KB |
Output is correct |
25 |
Correct |
304 ms |
76744 KB |
Output is correct |
26 |
Correct |
328 ms |
76744 KB |
Output is correct |
27 |
Correct |
395 ms |
76744 KB |
Output is correct |