Matrix
来源:互联网 发布:js检验只能输入数字 编辑:程序博客网 时间:2024/05/22 16:52
题目描述
数据范围n,a,b,Li,Ti<=10^5
一道水。。题。。
考虑一个位置(i,j)到(n,n)的会乘a^(n-j)*b^(n-i),还要乘一个系数为(i,j)到(n,n)的方案数(可以用组合数解决),预处理阶乘和逆元即可。
代码
#include<cstring>#include<algorithm>#include<cmath>#include<cstdio>#define fo(i,a,b) for(i=a;i<=b;i++)#define ll long long using namespace std;const int mo=1000000000+7;const int maxn=100000+5;int i,j,n;ll a,b,ans;ll am[maxn],bm[maxn],w[maxn*2],ni[maxn*2];ll qs(int x,int y){ if (y==0) return 1; ll s=qs(x,y/2);s=s*s%mo; if (y%2) s=s*x%mo; return s;}ll calc(int n,int m){ return w[n]*ni[m]%mo*ni[n-m]%mo;}int main(){ scanf("%d%lld%lld",&n,&a,&b); w[0]=ni[0]=1; fo(i,1,2*n) { w[i]=w[i-1]*i%mo; ni[i]=ni[i-1]*qs(i,mo-2)%mo; } am[0]=bm[0]=1; fo(i,1,n) am[i]=am[i-1]*a%mo,bm[i]=bm[i-1]*b%mo; fo(i,1,n){ ll x;scanf("%lld",&x); if (i>1){ b=bm[n-i];a=am[n-1]; ll c=calc(2*n-i-2,n-2); ans=(ans+a*b%mo*c%mo*x%mo)%mo; } } fo(i,1,n){ ll x;scanf("%lld",&x); if (i>1){ b=bm[n-1];a=am[n-i]; ll c=calc(2*n-i-2,n-2); ans=(ans+a*b%mo*c%mo*x%mo)%mo; } } printf("%lld\n",ans);}
0 0
- 《Matrix》
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- mAtrix
- Matrix
- matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- Matrix
- 清除应用的数据和关闭Wifi、BT、GPS,及清除wifi密码和wifi热点 .
- vector类型的形参
- 最大堆和堆排序学习笔记
- [51nod 1449]砝码称重
- IOS消息框,定时关闭
- Matrix
- 自定义cell里面添加button点击跳转别的界面
- FTP上传下载使用java(JSch技术)
- Objective-C利用GCD技术实现单例模式
- shrio的使用
- The file “” couldn’t be opened because you don’t have permission to view it.
- 解决win7/win8.1 驱动调试KdPrint不能输出的问题
- 本文介绍Android中的5种数据存储方式。
- 字符集合-- 华为2016研发工程师编程题