Gym 101480F Frightful Formula(待定系數)題解
阿新 • • 發佈:2019-05-07
map def bubuko cst mage inf 分享圖片 bsp name
#include<cmath> #include<set> #include<map> #include<queue> #include<cstdio> #include<vector> #include<cstring> #include <iostream> #include<algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull;const int maxn = 2e5 + 10; const int M = maxn * 30; const ull seed = 131; const int INF = 0x3f3f3f3f; const int MOD = 1e6 + 3; ll inv[maxn << 1], fac[maxn << 1]; ll ppow(ll a, ll b){ ll ret = 1; while(b){ if(b & 1) ret = ret * a % MOD; a = a * a % MOD; b>>= 1; } return ret; } void init(int n){ fac[0] = inv[0] = 1; for(int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % MOD; inv[n] = ppow(fac[n], MOD - 2); for(int i = n - 1; i >= 1; i--){ inv[i] = inv[i + 1] * (i + 1LL) % MOD; } } ll C(int n, int m){ if(m == 0) return 1; return fac[n] * inv[m] % MOD * inv[n - m] % MOD; } ll l[maxn], t[maxn]; ll dp[1000][1000]; int main(){ ll n, a, b, c; scanf("%lld%lld%lld%lld", &n, &a, &b, &c); init(n + n); ll k = c * ppow(a + b - 1, MOD - 2) % MOD; ll ans = 0; for(int i = 1; i <= n; i++) scanf("%lld", &l[i]), l[i] = (l[i] + k) % MOD; for(int i = 1; i <= n; i++) scanf("%lld", &t[i]), t[i] = (t[i] + k) % MOD; for(int i = 2; i <= n; i++){ ans = (ans + l[i] * C(n + n - i - 2, n - 2) % MOD * ppow(a, n - 1) % MOD * ppow(b, n - i) % MOD) % MOD; // printf("** %lld %lld\n", n + n - i - 2, n - 2); } for(int i = 2; i <= n; i++){ ans = (ans + t[i] * C(n + n - i - 2, n - 2) % MOD * ppow(a, n - i) % MOD * ppow(b, n - 1) % MOD) % MOD; } ans = ((ans - k) % MOD + MOD) % MOD; printf("%lld\n", ans); return 0; } /* 4 3 5 2 7 1 4 3 7 4 4 8 */ /* 3 2 3 0 1 1 1 1 1 1 */
Gym 101480F Frightful Formula(待定系數)題解