BJOJ 4402 Claris的剑 (组合数学,思维)
题目:传送门
题意
思路
大佬精讲
#include <bits/stdc++.h> #define LL long long #define ULL unsigned long long #define UI unsigned int #define mem(i, j) memset(i, j, sizeof(i)) #define rep(i, j, k) for(int i = j; i <= k; i++) #define dep(i, j, k) for(int i = k; i >= j; i--) #define pb push_back #define make make_pair #define INF 0x3f3f3f3f #define inf LLONG_MAX #define PI acos(-1) #define fir first #define sec second #define lb(x) ((x) & (-(x))) #define dbg(x) cout<<#x<<" = "<<x<<endl; using namespace std; const int N = 1e7 + 5; const LL mod = 1e9 + 7; LL fac[N], ifac[N]; LL ksm(LL a, LL b) { LL res = 1LL; while(b) { if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } LL C(int n, int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; } int n, m; void solve() { scanf("%d %d", &n, &m); fac[0] = ifac[0] = 1LL; rep(i, 1, n) fac[i] = 1LL * i * fac[i - 1] % mod; ifac[n] = ksm(fac[n], mod - 2); dep(i, 1, n - 1) ifac[i] = 1LL * (i + 1) * ifac[i + 1] % mod; LL ans = 1LL; rep(i, 0, min(m - 2, n - 2)) { ans = (ans + C(((n - i - 2) / 2) + i + 1, i + 1)) % mod; } rep(i, 0, min(m - 2, n - 3)) { ans = (ans + C(((n - i - 3) / 2) + i + 1, i + 1)) % mod; } printf("%lld\n", ans); } int main() { // int _; scanf("%d", &_); // while(_--) solve(); solve(); return 0; }
一步一步,永不停息