【找规律】【递推】【二项式定理】Codeforces Round #419 (Div. 1) B. Karen and Test
打个表出来看看,其实很明显。
推荐打这俩组
11
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000000

12
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000000 100000000000

打出表来看出来,n为偶数时,每隔两行,对原序列的奇数项分配的权重形成二项展开式。
n为奇数时,每隔四行,形成二项展开式。
所以只需要求出接近最后的某一行中的二项式系数即可。(有个O(n)的递推式可以直接求杨辉三角某一行的值)
最后距离答案已经不超过四行了,暴一下就行了。
#include<cstdio>
#include<cstring>
using namespace std;
#define MOD 1000000007ll
typedef long long ll;
ll n,nn;
ll a[200010],C[200010],b[10],c[10];
ll Quick_Pow(ll a,ll p)
{
if(!p) return 1;
ll ans=Quick_Pow(a,p>>1);
ans=ans*ans%MOD;
if((p&1)==1) ans=(a%MOD*ans)%MOD;
return ans;
}
int main(){
scanf("%I64d",&n);
for(ll i=1ll;i<=n;++i){
scanf("%I64d",&a[i]);
}
int tmp=0;
if(!(n&1ll)){
nn=n/2ll-1ll;
tmp=2;
}
else{
nn=n;
++tmp;
while((nn-1ll)%4ll!=0ll){
--nn;
++tmp;
}
nn/=2ll;
}
C[0]=1;
for(ll i=1ll;i<=nn;++i){
C[i]=((C[i-1]*(nn-(i-1ll)))%MOD*Quick_Pow(i,MOD-2ll))%MOD;
}
for(int i=1;i<=tmp;++i){
for(int j=i,k=0;j<=n;j+=2,++k){
b[i]=(b[i]+(a[j]%MOD*C[k])%MOD)%MOD;
}
}
ll sum=0;
for(ll i=n;i>(ll)tmp;--i){
sum+=(i-1ll);
}
bool op=(sum%2ll==0 ? 1 : 0);
for(int i=tmp;i>1;--i){
for(int j=1;j<i;++j){
if(op){
c[j]=b[j]+b[j+1];
}
else{
c[j]=b[j]-b[j+1];
}
op^=1;
}
memcpy(b,c,sizeof(c));
}
printf("%I64d\n",(b[1]+MOD)%MOD);
return 0;
}
【找规律】【递推】【二项式定理】Codeforces Round #419 (Div. 1) B. Karen and Test的更多相关文章
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
- 【递推】Codeforces Round #483 (Div. 2) [Thanks, Botan Investments and Victor Shaburov!] D. XOR-pyramid
题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i& ...
- Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...
- Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
- Codeforces Round #419 (Div. 2) C. Karen and Game
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- 【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game
容易发现,删除的顺序不影响答案. 所以可以随便删. 如果行数大于列数,就先删列:否则先删行. #include<cstdio> #include<algorithm> usin ...
- Codeforces Round #419 (Div. 1) C. Karen and Supermarket 树形DP
C. Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some g ...
随机推荐
- bzoj 2786 DP
我们可以将=左右的两个数看成一个块,块内无顺序要求,把<分隔的看成两个块,那么我们设w[i][j]代表将i个元素分成j个块的方案数,那么显然w[i][j]=w[i-1][j]*j+w[i-1][ ...
- 【bug】vue-cli 3.0报错的解决办法
先上bug图片 bug说明:初装vue_cli3.0写了个组件,运行错误,显示如图, 代码提示:[Vue warn]: You are using the runtime-only build of ...
- Java的9种基本数据类型的大小,以及他们的封装类
由于java程序是运行在虚拟机之上的,所以java的基本数据类型的大小是确定的,不会随着操作系统的位数的改变而改变. 在计算机中,存储的是0,1,0,1这样的二进制位,表示为bit,1Byte = 8 ...
- linux网络编程之IO函数
Linux操作系统中的IO函数主要有read(),write(),recv(),send(),recvmsg(),sendmsg(),readv(),writev(). 接收数据的recv()函数 # ...
- python近期遇到的一些面试问题(一)
整理一下最近被问到的一些高频率的面试问题.总结一下方便日后复习巩固用,同时希望可以帮助一些朋友们. 1.python的基本数据类型 主要核心类型分为两类不可变类型:数字(int float bool ...
- 【bzoj1798】【AHOI2009】维护序列
练一下线段树模板,区间乘法. #include<bits/stdc++.h> #define lson (o<<1) #define rson (o<<1|1) ; ...
- C基础 内存统一入口
引言 - malloc 引述 C标准中堆上内存入口就只有 malloc, calloc, realloc . 内存回收口是 free. 常见的一种写法是 struct person * per = ...
- LVS负载均衡DR模式
什么是集群? 一组相互独立的计算机,利用高速通信网络组成的一个计算机系统,对于客户机来说像是一个单一服务器,实际上是一组服务器.简而言之,一堆机器协同工作就是集群.集群的基本特点:高性能.高并发.高吞 ...
- mac date 和 Linux date实现从指定时间开始循环
Linux date begin="2016-01-01" ; i < ; i++ )); do current=$(date -d "$i day $begin& ...
- Activiti如何替换已部署流程图
首先交代下背景:我们有一个已经上线的activiti工作流系统,对于流程图的操作已经封装好部署,查看,删除的接口.此时客户提出要修改个别流程图里的节点名称. 我的第一个想法就是本地修改流程图bpmn文 ...