Gym 101480F Frightful Formula(待定系数)题解
#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(待定系数)题解的更多相关文章
- Frightful Formula Gym - 101480F (待定系数法)
Problem F: Frightful Formula \[ Time Limit: 10 s \quad Memory Limit: 512 MiB \] 题意 题意就是存在一个\(n*n\)的矩 ...
- LG4351 [CERC2015]Frightful Formula
Frightful Formula 给你一个\(n\times n\)矩阵的第一行和第一列,其余的数通过如下公式推出: \[f_{i,j}=a\cdot f_{i,j-1}+b\cdot f_{i-1 ...
- bzoj 4451 : [Cerc2015]Frightful Formula FFT
4451: [Cerc2015]Frightful Formula Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 177 Solved: 57[Sub ...
- Codeforces GYM 100876 J - Buying roads 题解
Codeforces GYM 100876 J - Buying roads 题解 才不是因为有了图床来测试一下呢,哼( 题意 给你\(N\)个点,\(M\)条带权边的无向图,选出\(K\)条边,使得 ...
- BZOJ4451 [Cerc2015]Frightful Formula 多项式 FFT 递推 组合数学
原文链接http://www.cnblogs.com/zhouzhendong/p/8820963.html 题目传送门 - BZOJ4451 题意 给你一个$n\times n$矩阵的第一行和第一列 ...
- BZOJ4451 : [Cerc2015]Frightful Formula
$(i,1)$对答案的贡献为$l_iC(2n-i-2,n-i)a^{n-1}b^{n-i}$. $(1,i)$对答案的贡献为$t_iC(2n-i-2,n-i)*a^{n-i}b^{n-1}$. $(i ...
- URAL1519:Formula 1——题解
http://acm.timus.ru/problem.aspx?space=1&num=1519 https://vjudge.net/problem/URAL-1519 题目大意:给一个网 ...
- P4351-[CERC2015]Frightful Formula【组合数学,MTT】
正题 题目链接:https://www.luogu.com.cn/problem/P4351 题目大意 \(n*n\)的矩形,给出第一行和第一列的数,剩下的满足\(F_{i,j}=a*F_{i,j-1 ...
- Gym - 101480 CERC 15:部分题目题解(队内第N次训练)
-------------------题目难度较难,但挺有营养的.慢慢补. A .ASCII Addition pro:用一定的形式表示1到9,让你计算加法. sol:模拟. solved by fz ...
随机推荐
- jmeter报Address already in use: connect
jmeter报Address already in use: connect 用windows进行jmeter压测出现java.net.BindException: Address already ...
- MySQL的双主配置
配置MySQL双主配置,需要先配置MySQL的主从复制,传送门: 0.集群规划 hadoop105 hadoop106 hadoop107 MySQL(master,slave) MySQL(slav ...
- UDP flood UDP Port Denial-of-Service Attack
https://baike.baidu.com/item/UDP%20flood/5504851 UDPFlood是日渐猖厥的流量型DoS攻击,原理也很简单.常见的情况是利用大量UDP小包冲击DNS服 ...
- CF413C
正文 题意: 给 n 个关卡,每个关卡得分为 ai,有 m 次机会可以选择一 个关卡通过后不得分,而将现有得分翻倍 你可以安排关卡的通过顺序和策略,求最大得分. 分析: 看到这道题首先想到的就是贪心, ...
- svn 启动项目报错,项目被lock
问题描述 问题解决 (一)Eclipse SVN 插件处理 (二)SVN 客户端处理 (三)删除lock文件 问题描述 在使用开发工具开发项目时(如Eclipse),在做项目的中途,有时候Eclips ...
- Mysql 5.5升级5.8
前言,因为升级跳板机,需要将mariadb 升级到10.2,也就是对应MySQL的5.8,废话不多说下面开始进行mariadb 5.5 的升级 Welcome to the MariaDB monit ...
- 云服务器镜像问题("Couldn't resolve host 'mirrors.tencentyun.com')
云服务器镜像问题("Couldn't resolve host 'mirrors.tencentyun.com') 原因: 腾讯云服务器内网yum源的域名 mirrors.tencentyu ...
- 设计模式(七)——适配器模式(SpringMVC框架分析)
适配器模式 1 现实生活中的适配器例子 泰国插座用的是两孔的(欧标),可以买个多功能转换插头 (适配器) ,这样就可以使用了. 2 基本介绍 1) 适配器模式(Adapter Pattern)将某个类 ...
- 正点原子DS100拆解全过程-硬件工程师必备
前言: 之前一篇只针对正点原子DS100手持示波器的使用介绍文章.可作为一个电子工程师,光使用不是我们的风格哈,我们还要拆开看看电路. 开拆 外壳 首先,看下图,DS100不是使用螺母进行固定的,而是 ...
- STL_优先队列
一.简介 优先队列容器与队列一样,只能从队尾插入元素,从队首删除元素.但是它有一个特性,就是队列中最大的元素总是位于队首,所以出队时,并非按照先进先出的原则进行,而是将当前队列中最大的元素出队. 元素 ...