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

推荐打这俩组

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. 4、什么是事务?MySQL如何支持事务?

    什么是事务? 事务是由一步或几步数据库操作序列组成逻辑执行单元,这系列操作要么全部执行,要么全部放弃执行.程序和事务是两个不同的概念.一般而言:一段程序中可能包含多个事务.(说白了就是几步的数据库操作 ...

  2. bzoj 1179 tarjan+spfa

    首先我们可以将这个图缩成DAG,那么问题中的路线就可以简化为DAG中的一条链,那么我们直接做一遍spfa就好了. 反思:开始写的bfs,结果bfs的时候没有更新最大值,而是直接赋的值,后来发现不能写b ...

  3. tensorflow常用函数解析

    一.tf.transpose函数的用法 tf.transpose(input, [dimension_1, dimenaion_2,..,dimension_n]):这个函数主要适用于交换输入张量的不 ...

  4. handle_level_irq 与handle_edge_irq 的区别【转】

    转自:http://blog.csdn.net/xavierxiao/article/details/6087277 版权声明:本文为博主原创文章,未经博主允许不得转载. Linux 里, handl ...

  5. java===字符串常用API介绍(转)

    本文转自:http://blog.csdn.net/crazy_kid_hnf/article/details/55102861 字符串基本操作 1.substring(from,end)(含头不含尾 ...

  6. linux===Ubuntu修改设备名称

    step1 sudo vim /etc/hostname 修改你需要的,保存退出 step2 sudo vim /etc/hosts 修改你需要的,保存退出 step3 reboot

  7. 我的新博客地址http://xxxbw.github.io/

    最近在学github,在github搭了个博客,以后也会使用另外一个博客.有兴趣的小伙伴可以看看~ 地址:http://xxxbw.github.io/

  8. 使用 Visual Studio 部署 .NET Core 应用 ——.Net Core 部署到SUSE Linux Enterprise Server 12 SP2 64 位(GNOME 版本3.20.2)

    SUSE Linux安装 apache 命令:sudo zypper in apache 设置apache 服务可用 命令:sudo systemctl enable apache2.service启 ...

  9. POJ-1830

    开关问题 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6294   Accepted: 2393 Description ...

  10. 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记9——游戏摄像机&三维地形的构建

    第21章 游戏摄像机的构建 之前的程序示例,都是通过封装的DirectInput类来处理键盘和鼠标的输入,对应地改变我们人物模型的世界矩阵来达到移动物体,改变观察点的效果.其实我们的观察方向乃至观察点 ...