题目链接:http://codeforces.com/contest/816/problem/D

题解:显然一看到这题应该会想到是有什么规律的于是多写几项就会发现偶数列之间是有关系的。

满足a[i][j]=a[i-2][j]+a[i-2][j+2],于是递推到最后第2列a[2][0],a[2][1]就可以用最早出现的偶数列来求的,最后是加还是减只要看n就行了。

由于a[2][0]是有几个最早出现的偶数列的奇数项求的,而且这些奇数项选择的次数符合二项式分布(这个可以通过花一下杨辉三角理解一下)。

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#define mod 1000000007
using namespace std;
const int M = 2e5 + 10;
typedef long long ll;
ll anum[M] , bnum[M] , up[M] , down[M];
ll inv(ll a) {
return a == 1 ? 1 : (ll)(mod - mod / a) * inv(mod % a) % mod;
}
//ll C(ll n , ll m)
//{
// if(m < 0)return 0;
// if(n < m)return 0;
// if(m > n-m) m = n-m;
// ll up = 1, down = 1;
// for(ll i = 0 ; i < m ; i++){
// up = up * (n-i) % mod;
// down = down * (i+1) % mod;
// }
// return up * inv(down) % mod;
//}//原先利用逆元的算法,但是这里直接求会超时与处理一下up和down就行。
int main() {
int n;
scanf("%d" , &n);
for(int i = 0 ; i < n ; i++) scanf("%lld" , &anum[i]) , bnum[i] = anum[i];
if(n == 1) {printf("%lld\n" , anum[0]); return 0;}
if(n & 1) {
n--;
int flag = 1;
for(int i = 0 ; i < n ; i++) {
if(flag) anum[i] = (bnum[i] + bnum[i + 1]) % mod;
else anum[i] = (bnum[i] - bnum[i + 1] + mod) % mod;
flag ^= 1;
}
}
n = n / 2 - 1;
ll ans1 = 0 , ans2 = 0;
up[0] = 1 , down[0] = 1;
for(int i = 1 ; i <= n / 2 ; i++) up[i] = up[i - 1] * (n - i + 1) % mod , down[i] = down[i - 1] * i % mod;
for(int i = n / 2 + 1 ; i <= n ; i++) up[i] = up[n - i] , down[i] = down[n - i];
for(int i = 0 ; i <= n ; i++) {
ans1 += anum[2 * i] * (up[i] * inv(down[i]) % mod) % mod;
ans1 %= mod;
ans2 += anum[2 * i + 1] * (up[i] * inv(down[i]) % mod) % mod;
ans2 %= mod;
}
if(n % 2) ans1 = (ans1 - ans2 + mod) % mod;
else ans1 = (ans1 + ans2) % mod;
printf("%lld\n" , ans1);
return 0;
}

codeforces 816 D. Karen and Test(逆元+思维+组合数)的更多相关文章

  1. codeforces 816 B. Karen and Coffee(思维)

    题目链接:http://codeforces.com/contest/816/problem/B 题意:给出n个范围,q个查询问查询区间出现多少点在给出的n个范围中至少占了k次 题解:很显然的一道题目 ...

  2. codeforces 816 C. Karen and Game(模拟+思维)

    题目链接:http://codeforces.com/contest/816/problem/C 题意:给出一个矩阵,问能否从都是0的情况下只将一整行+1或者一整列+1变形过来,如果可以输出需要步数最 ...

  3. codeforces 816 E. Karen and Supermarket(树形dp)

    题目链接:http://codeforces.com/contest/816/problem/E 题意:有n件商品,每件有价格ci,优惠券di,对于i>=2,使用di的条件为:xi的优惠券需要被 ...

  4. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  5. Educational Codeforces Round 88 (Rated for Div. 2) E、Modular Stability 逆元+思维

    题目链接:E.Modular Stability 题意: 给你一个n数,一个k,在1,2,3...n里挑选k个数,使得对于任意非负整数x,对于这k个数的任何排列顺序,然后用x对这个排列一次取模,如果最 ...

  6. codeforces 349B Color the Fence 贪心,思维

    1.codeforces 349B    Color the Fence 2.链接:http://codeforces.com/problemset/problem/349/B 3.总结: 刷栅栏.1 ...

  7. Codeforces 816C/815A - Karen and Game

    传送门:http://codeforces.com/contest/816/problem/C 本题是一个模拟问题. 有一个n×m的矩阵.最初,这个矩阵为零矩阵O.现有以下操作: a.行操作“row  ...

  8. 【codeforces 816C】Karen and Game

    [题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全 ...

  9. 【codeforces 816B】Karen and Coffee

    [题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k ...

随机推荐

  1. EasyUI combobox下拉列表实现搜索过滤(模糊匹配)

    项目中的某个下拉列表长达200多个项,这么巨大的数量一个一个找眼镜都得看花,于是就得整了个搜索功能.看网上别人帖子有只能前缀匹配的方案,但只能前缀匹配的话用起来也不是很方便.于是就记录一下模糊匹配的方 ...

  2. c#将字符串转化为合理的文件名

    string name = System.Text.RegularExpressions.Regex.Replace(url, "[<>/\\|:\"?*]" ...

  3. Java实现调用Bartender控制条码打印机

    官方提供的主要是C#支持. 基于java调用bartender二次开发官方给了一份1998年的J#代码,,,完全用不了,,,百度谷歌搜索万能的网友的答案,发现也没有可参考的.. 最后想到了之前用到了一 ...

  4. ASP.NET Core MVC 之控制器(Controller)

    操作(action)和操作结果(action result)是 ASP.NET MVC 构建应用程序的一个基础部分. 在 ASP.NET MVC 中,控制器用于定义和聚合一组操作.操作是控制器中处理传 ...

  5. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  6. Python3基本数据类型之列表

    1.初识列表 列表(List)是Python3中的"容器型"数据类型. 列表通过中括号把一堆数据括起来的方式形成,列表的长度不限. 列表里面的元素可以是不同的数据类型,但是一般是相 ...

  7. html5新特性-header,nav,footer,aside,article,section等各元素的详解

    Html5新增了27个元素,废弃了16个元素,根据现有的标准规范,把HTML5的元素按优先级定义为结构性属性.级块性元素.行内语义性元素和交互性元素四大类. 下面是对各标签的详解,section.he ...

  8. RedHat 6.5换源

    https://wenku.baidu.com/view/5b87fb42c77da26924c5b03b.html

  9. OSI七层网络模型与TCP/IP四层模型

    1.OSI七层结构图: 2.TCP/IP四层结构图: 3.各层对应的协议 4.OSI七层和TCP/IP四层的区别 OSI网络模型和TCP/IP网络模型对应关系: 5.交换机工作在OSI的哪一层 如果有 ...

  10. 运行MonkeyRunner时使用Genymotion模拟器

    Android自带的模拟器实在太慢太卡,远没有Genymotion的顺畅,所以找了一个办法,在启动py文件时使用Genymotion的模拟器 1.Genymotion安装完成之后,在Settings- ...