Codeforces 815B. Karen and Test 【规律】
来源:互联网 发布:linux属于应用软件吗 编辑:程序博客网 时间:2024/05/17 01:43
-------
当n为偶数时: n/2为奇数时: c[2*k+1]=c[2*k+2]=Y[n/2][k] n/2为偶数时: c[2*k+1]=Y[n/2][k] c[2*k+2]=-Y[n/2][k]
#include<stdio.h>#include<bits/stdc++.h>#define ll long long#define pii pair<int,int>#define MEM(a,x) memset(a,x,sizeof(a))#define lowbit(x) ((x)&-(x))using namespace std;const int inf=0x3f3f3f3f;const int MOD = 1e9+7;const int N = 200000 + 5;ll a[N],c[N],fact[N];void initFact(){ fact[0]=fact[1]=1; for(int i=2;i<N;++i){ fact[i]=(i*fact[i-1])%MOD; }}ll ny(ll x){ int n=MOD-2; ll ans=1,t=x; while(n){ if(n&1){ ans=(ans*t)%MOD; } n>>=1; t=(t*t)%MOD; } return ans;}ll C(ll n,ll k){ ll fz=fact[n]; ll fm=(fact[n-k]*fact[k])%MOD; fm=ny(fm); return (fz*fm)%MOD;}int slove(int n){ int tn=n/2; int idx=0; for(int i=0;i<tn;++i){ c[idx++]=C(tn-1,i); if(tn&1){ c[idx]=c[idx-1]; } else{ c[idx]=-c[idx-1]; } ++idx; } ll ans=0; for(int i=0;i<n;++i){ ans=(ans+c[i]*a[i])%MOD; } return (ans+MOD)%MOD;}int main(){ //freopen("/home/lu/code/r.txt","r",stdin); int n; initFact(); while(~scanf("%d",&n)){ for(int i=0;i<n;++i){ scanf("%lld",a+i); } if(n==1){ printf("%lld\n",a[0]); continue; } if(n&1){ int flag=1; for(int i=0;i<n-1;++i){ a[i]=a[i]+flag*a[i+1]; flag*=-1; } --n; } printf("%d\n",slove(n)); } return 0;}
阅读全文
0 0
- Codeforces 815B. Karen and Test 【规律】
- Codeforces 815B Karen and Test
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- [数学杂题]Codeforces #419(div1) 815B. Karen and Test
- CodeForces B. Karen and Coffee
- Codeforces 816D Karen and Test
- codeforces 816D Karen and Test(数学)
- Codeforces Round #419 (Div. 1) B. Karen and Test(组合数)
- Codeforces Round #419 B. Karen and Test (思维 + 组合数 + 乘法逆元)
- Karen and Coffee codeforces 816B
- Codeforces 816 -B. Karen and Coffee
- Codeforces 816B-Karen and Coffee
- Codeforces 816B Karen and Coffee
- CodeForces 815D. Karen and Cards
- Codeforces 815A-Karen and Game
- CodeForces 815E Karen and Neighborhood题解
- Karen and Coffee codeforces
- Karen and Game Codeforces
- vue2移动端上传,预览,压缩图片,解决拍照旋转问题
- 一台windows主机安装多个mysql服务
- Codeforces Gym 101174 E. Passwords (AC 自动机 + DP)
- Accept与Content-type区别
- 计算机网络知识总结:
- Codeforces 815B. Karen and Test 【规律】
- Springboot系列:@SpringBootApplication注解
- Android中小数处理(DecimalFormat)
- 用springmvc实现类似restful风格接口(接收和返回为xml格式数据)
- git的使用
- c语言课程设计-学生成绩管理系统
- SSH协议原理
- Codeforces Gym F. Performance Review (树状数组 + DFS 序)
- 回文串题目总结