CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)
You've got an array a, consisting of n integers. The array elements are indexed from 1 to n. Let's determine a two step operation like that:
First we build by the array a an array s of partial sums, consisting of n elements. Element number i (1 ≤ i ≤ n) of array s equals . The operation x mod y means that we take the remainder of the division of number x by number y.
Then we write the contents of the array s to the array a. Element number i (1 ≤ i ≤ n) of the array s becomes the i-th element of the array a (ai = si).
You task is to find array a after exactly k described operations are applied.
Input
The first line contains two space-separated integers n and k (1 ≤ n ≤ 2000, 0 ≤ k ≤ 109). The next line contains n space-separated integers a1, a2, ..., an — elements of the array a (0 ≤ ai ≤ 109).
Output
Print n integers — elements of the array a after the operations are applied to it. Print the elements in the order of increasing of their indexes in the array a. Separate the printed numbers by spaces.
Examples
Input
3 1
1 2 3
Output
1 3 6
Input
5 0
3 14 15 92 6
Output
3 14 15 92 6
如果把a1,a2,a3....an的系数取出,会有如下规律1,11,111,1111 C00C10C20C301,21,321,4321,54321 C11C21C31C411,31,631,10 631 C22C32C42C52如果把a1,a2,a3....an的系数取出,会有如下规律\\
1 , 1 1,111,1111 \ C^0_0C^0_1C^0_2C^0_3\\
1,21,321,4321,54321\ C^1_1C^1_2C^1_3C^1_4\\
1,31,631,10\ 631\ C^2_2C^2_3 C^2_4C^2_5如果把a1,a2,a3....an的系数取出,会有如下规律1,11,111,1111 C00C10C20C301,21,321,4321,54321 C11C21C31C411,31,631,10 631 C22C32C42C52
这个题用lucas过不了,卡时间,然后写递推,感谢SHDL写的递推板子
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
int f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
typedef long long ll;
//---------------https://lunatic.blog.csdn.net/-------------------//
#define MOD 1000000007
// LL quickPower(LL a, LL b)
// {
// LL ans = 1;
// a %= MOD;
// while (b)
// {
// if (b & 1)
// {
// ans = ans * a % MOD;
// }
// b >>= 1;
// a = a * a % MOD;
// }
// return ans;
// }
// LL c(LL n, LL m)
// {
// if (m > n)
// {
// return 0;
// }
// LL ans = 1;
// for (int i = 1; i <= m; i++)
// {
// LL a = (n + i - m) % MOD;
// LL b = i % MOD;
// ans = ans * (a * quickPower(b, MOD - 2) % MOD) % MOD;
// }
// return ans;
// }
// LL lucas(LL n, LL m)
// {
// if (m == 0)
// {
// return 1;
// }
// return c(n % MOD, m % MOD) * lucas(n / MOD, m / MOD) % MOD;
// }
ll power(ll a, ll b, ll p)
{
ll ans = 1 % p;
for (; b; b >>= 1)
{
if (b & 1)
ans = ans * a % p;
a = a * a % p;
}
return ans;
}
long long b[20005], ans[20005], mm[500000];
void init(ll n, ll k)
{
mm[1] = 1;
for (ll i =2; i <= n; i++)
{
mm[i] = ((mm[i - 1] * (k + i - 2)) % MOD * power(i - 1, MOD - 2, MOD)) % MOD;
//cout<<mm[i]<<endl;
}
}
int main()
{
int n, k;
read(n), read(k);
init(n,k);
for (int i = 1; i <= n; i++)
{
read(b[i]);
for (int j = i; j >= 1; j--)
{
ans[i] += (mm[i-j+1] * b[j]) % MOD;
ans[i] %= MOD;
}
}
for (int i = 1; i <= n; i++)
// k == 0 ? wl(b[i]) :
wl(ans[i]);
puts("");
}
CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)的更多相关文章
- CF思维联系--CodeForces - 218C E - Ice Skating (并查集)
题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...
- CF思维联系– CodeForces - 991C Candies(二分)
ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...
- CF思维联系–CodeForces - 225C. Barcode(二路动态规划)
ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...
- CF思维联系–CodeForces -224C - Bracket Sequence
ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...
- CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)
ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...
- CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)
ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...
- CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)
Nastya received a gift on New Year - a magic wardrobe. It is magic because in the end of each month ...
- Codeforces 1106F Lunar New Year and a Recursive Sequence (数学、线性代数、线性递推、数论、BSGS、扩展欧几里得算法)
哎呀大水题..我写了一个多小时..好没救啊.. 数论板子X合一? 注意: 本文中变量名称区分大小写. 题意: 给一个\(n\)阶递推序列\(f_k=\prod^{n}_{i=1} f_{k-i}b_i ...
- Codeforces Round #627 (Div. 3) E - Sleeping Schedule(递推)
题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点 ...
随机推荐
- 团队项目-运动App
一:团队成员介绍 队长:温学智 博客地址:https://www.cnblogs.com/dazhi151/ 技术型大佬,学习能力相对团队来说是最高的.并且作为班 ...
- mysql的事务四个特性以及事务的四个隔离级别
一.事务四大属性 分别是原子性.一致性.隔离性.持久性. 1.原子性(Atomicity) 原子性是指事务包含的所有操作要么全部成功,要么全部失败回滚,因此事务的操作如果成功就必须要完全应用到数据库, ...
- Codeup 25609 Problem I 习题5-10 分数序列求和
题目描述 有如下分数序列 2/1,3/2,5/3,8/5,13/8,21/13 - 求出次数列的前20项之和. 请将结果的数据类型定义为double类型. 输入 无 输出 小数点后保留6位小数,末尾输 ...
- CentOS7安装JAVA环境
安装JAVA环境我常用的有两种形式 1.下载tar包安装 2.下载rpm包直接安装 本篇内容就写这两种形式的安装方法: JAVA程序的下载地址:https://www.oracle.com/java/ ...
- stand up meeting 12/7/2015
part 组员 今日工作 工作耗时/h 明日计划 工作耗时/h UI 冯晓云 ------------------ -- --------------------- --- PDF Rea ...
- Key Set HDU - 5363
这个题目套公式 2^(n-1)-1,再来个快速幂基本上就可以AC了 写这个题目的: 公式容易推到错: 容易写成 2^n-1/2...这样写出来结果也不错 但是一直哇 AC: #include< ...
- django.template.exceptions.TemplateDoesNotExist: login.html报错
前言 在某一次按以前的步骤使用Django “django.template.exceptions.TemplateDoesNotExist: login.html”错误,在以为是html文件出 ...
- Python爬取养眼图片
1.准备 各位绅士们,你可能会觉得疫情在家无聊,那么现在我们的Python语言可以满足你们的需求.项目需要的工具(1)Python3(2)requests库requests库可以通过代码pip ins ...
- windows下常用快捷指令记忆
快速打开环境变量窗口 sysdm.cpl --系统设置 快速打开远程桌面程序 mstsc ---Microsoft terminal services client 快速打开事件查看器 eventvw ...
- 分析PE
PE文件是Windows平台下可执行文件标准格式,浓缩了微软工程师的设计精华,历经40年依旧保持着原有的设计.分析PE文件对于研究Windows操作系统有着重要的实践意义,对于逆向分析有着重要的指导作 ...