题目链接: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. 显示Mac隐藏文件的命令:

    设置查看隐藏文件的方法如下:打开终端,输入命名 显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏 ...

  2. codeforces 327 A Ciel and Dancing

    题目链接 给你一串只有0和1的数字,然后对某一区间的数翻转1次(0变1 1变0),只翻转一次而且不能不翻转,然后让你计算最多可能出现多少个1. 这里要注意很多细节 比如全为1,要求必须翻转,这时候我们 ...

  3. jdk8与jdk7中hashMap的resize分析

    在分析代码之前,我们先抛出下面的问题: hashmap 扩容时每个 entry 需要再计算一次 hash 吗? 我们首先看看jdk7中的hashmap的resize实现 1 void resize(i ...

  4. 证明线程池ThreadPoolExecutor的核心线程数,最大线程数,队列长度的关系

    关于线程池的几个参数,很多人不是很清楚如何配置,他们之间是什么关系,我用代码来证明一下. package www.itbac.com; import java.util.concurrent.*; p ...

  5. PythonDay05

    第五章 今日内容 字典 字典 语法:{'key1':1,'key2':2} 注意:dict保存的数据不是按照我们添加进去的顺序保存的. 是按照hash表的顺序保存的. ⽽hash表 不是连续的. 所以 ...

  6. 【Java例题】5.1 多项式计算

    1. 计算下列多项式的值. pn=an*x^n+...+a1*x+a0其中,"^"表示乘方. x.n以及ai(i=0,1,...,n-1)由键盘输入. package chapte ...

  7. BFS DFS模板

    转载于https://blog.csdn.net/alalalalalqp/article/details/9155419 BFS模板: #include<cstdio> #include ...

  8. temperatureConversion1

    (原题:https://www.python123.io/student/courses/934/groups/8102/problems/programmings/6078) Solution: # ...

  9. Go类型别名与类型定义区别

    类型别名和自定义类型区别 自定义类型 //自定义类型是定义了一个全新的类型 //将MyInt定义为int类型 type MyInt int 类型别名 //类型别名规定:TypeAlias只是Type的 ...

  10. vs中代码的发行以及图标的添加

    发布代码,将Debug改成Release 在属性代码生成中找到运行库将多线程MD改成MT应用(使文件适用于普遍的电脑) 重新生成解决方案然后就可以在项目文件夹中找到Release底下的.exe文件(可 ...