【找规律】【递推】【二项式定理】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 ...
随机推荐
- Angular2.0 基础: Form
对于Angular2.0 的Form表单中的隐藏和验证,个人觉得还是挺有意思的. 1.通过ngModel 跟踪修改状态与验证. 在表单中使用 ngModel 可以获得更多的控制权,包括一些常用的验证. ...
- windows+nexus+maven环境搭建(转)
windows nexus环境搭建 1.下载nexus 版本为 nexus-2.11.4-01-bundle 下载地址 这里写链接内容 2.将下载好的文件放到D盘进行解压 3.解压后目录结构 nexu ...
- 【转】png文件格式
前言 我们都知道,在进行J2ME的手机应用程序开发的时候,在图片的使用上,我们可以使用PNG格式的图片(甚至于在有的手机上,我们只可以使用PNG 格式的图片),尽管使用图片可以为我们的应用程序增加不少 ...
- [Leetcode Week13]Palindrome Partitioning
Palindrome Partitioning 题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/palindrome-partitioning/desc ...
- 在linux程序里面,知道一个函数地址,改函数是属于某个动态库的,怎么样得到这个动态库的全【转】
转自:http://www.360doc.com/content/17/1012/11/48326749_694292472.shtml 另外dl_iterate_phdr可以查到当前进程所装在的所有 ...
- Linux进程调度与源码分析(二)——进程生命周期与task_struct进程结构体
1.进程生命周期 Linux操作系统属于多任务操作系统,系统中的每个进程能够分时复用CPU时间片,通过有效的进程调度策略实现多任务并行执行.而进程在被CPU调度运行,等待CPU资源分配以及等待外部事件 ...
- Yii 1.1.17 四、属性标签、AR类增删改查、使用上传类与扩展第三方类库
一.属性标签与规则设置 当进入网站页面,将会读数据库返回信息到视图上.那么,现在定义模型中的属性在视图标签上的显示, 也就是模型属性到前台标签的映射 // 定义模型属性到前台标签的映射 public ...
- python实战===爬取所有微信好友的信息
''' 爬取所有T信好友的信息 ''' import itchat from pandas import DataFrame itchat.login() friends=itchat.get_fri ...
- monkey测试===ios-monkey测试工具
iOSmonkey测试工具: crashmonkey 特点: 支持**真机测试.模拟器测试** 支持收集**系统日志(Systemlog)**.**崩溃日志(Crashlog)**.***instru ...
- 【模板】BZOJ 3781: 小B的询问 莫队算法
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 N个数的序列,每次询问区间中每种数字出现次数的平方和,可以离线. 丢模板: #include ...