CF1288C Two Arrays

\ (\ large {topic Link} \)
\ (\\\)
\ (\ Large \ textbf {Solution:} \ {1.DP Large, see \ TLx Blog of XYX} {text} \) \ (\ Large { \ TLx Blog {text}} \) \ (\\\)
\ (\ \ Quad \ Quad \ Quad \ Quad \ Quad \ Quad \) \ (\ {2 Large. separator by the method, the program number of C ^ { n-1} _ {2m- n + 1}, and then to linear inversing. kind \\ \ text {O (n)} of the inverse factorial method, inv \ left [n + 1 \ right] = \ dfrac {1} {\ left (n + 1 \ right)!}, it is possible to reverse the introduction of an inverse element, inv \ left [i + 1 \ right] \ times \ left (i + 1 \ right) = \ dfrac . 1 {} {!} I = INV \ left [I \ right]} \).
\ (\\\)
\ (\ Large \ Code textbf {:} \)

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 4010; 
const int p = 1e9 + 7;

int n, m;
ll inv[N], s[N];

int read() {
	int x = 0;
	char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x; 
}

inline ll quickpow(ll a, ll b) {
	ll base = a, ans = 1;
	for (; b ; b >>= 1, base = (base * base) % p) if (b & 1) ans = (ans * base) % p;
	return ans;
}

int main() {
	n = read(), m = read();
	s[1] = 1;
	for (int i = 2; i <= 3010; ++i) s[i] = (s[i - 1] * i) % p;
	inv[3010] = quickpow(s[3010], p - 2);
	for (int i = 3009; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % p;
	printf("%lld\n", s[n + 2 * m - 1] * inv[n - 1] % p * inv[m << 1] % p);
	return 0;
} 

Guess you like

Origin www.cnblogs.com/Miraclys/p/12609297.html