打个表出来看看,其实很明显。

推荐打这俩组

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的更多相关文章

  1. 递推DP Codeforces Round #260 (Div. 1) A. Boredom

    题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...

  2. 【递推】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& ...

  3. Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)

    http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...

  4. 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 ...

  5. Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)

    http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...

  6. 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 ...

  7. 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 ...

  8. 【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game

    容易发现,删除的顺序不影响答案. 所以可以随便删. 如果行数大于列数,就先删列:否则先删行. #include<cstdio> #include<algorithm> usin ...

  9. 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 ...

随机推荐

  1. Angular2.0 基础: 环境搭建

    最近在学习Angular2的使用,其实看过Angular2 文档的都知道,相比于之前的Angular1,Angular2 的改动还是挺大的. 而对于‘angular2 的本地开发环境的搭建的中,我们首 ...

  2. Python模块学习 - click

    Click模块 click模块是Flask的作者开发的一个第三方模块,用于快速创建命令行.它的作用与Python标准库的argparse相同,但是,使用起来更简单. click是一个第三方库,因此使用 ...

  3. Linux 入门记录:十四、网络基础

    一.IP地址 IP 地址是因特网上的每个网络节点在全球范围内的唯一标识符,一个 IP 地址唯一标识一个主机(严格来说是标识一个网卡接口 network interface card). 现在应用最为广 ...

  4. ThinkPHP5 正则验证中有“|”时提示“规则错误”的解决方案

    正则规则中有“|”时,会引起解析错误: 'regex:\d{3,4}[\s,-]?\d{7,8}|1[3,4,5,8]\d[\s,-]?\d{4}[\s,-]?\d{4}' 使用数组语法可以解决: [ ...

  5. 《gdb调试之基础篇》

    <gdb调试之基础篇> http://blog.csdn.net/miss_acha/article/details/42346543

  6. 算法题之Median of Two Sorted Arrays

    这道题是LeetCode上的题目,难度级别为5,刚开始做没有找到好的思路,以为是自己智商比较低,后来发现确实也比较低... 题目: There are two sorted arrays nums1  ...

  7. 网站服务器压力Web性能测试(4):服务器压力Web性能测试小结

    1.Apache Bench,Webbench,http_load对网站压力Web性能进行测试时,为了得到更加客观和准确的数值,应该从远程访问.局域网访问和本地等多个方面进行全方位的测试.一般用127 ...

  8. android 图片透明

    在ImageButton中载入图片后,图片周围会存在一圈白边,会影响到美观,其实解决这个问题有两种方法 一种方法是将ImageButton的背景改为所需要的图片.如:android:backgroun ...

  9. [hadoop][基本原理]zookeeper简单使用

    代码:https://github.com/xufeng79x/ZkClientTest 1.简介 zookeeper的基本原理和使用场景描述可参考:[hadoop][基本原理]zookeeper基本 ...

  10. The content of element type "resultMap" must match "(constructor?,id*,result*,association*,collectio

    The content of element type "resultMap" must match "(constructor?,id*,result*,associa ...