ACM思维题训练集合

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 C00​C10​C20​C30​1,21,321,4321,54321 C11​C21​C31​C41​1,31,631,10 631 C22​C32​C42​C52​

这个题用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(组合数学的先线性递推)的更多相关文章

  1. CF思维联系--CodeForces - 218C E - Ice Skating (并查集)

    题目地址:24道CF的DIv2 CD题有兴趣可以做一下. ACM思维题训练集合 Bajtek is learning to skate on ice. He's a beginner, so his ...

  2. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  3. CF思维联系–CodeForces - 225C. Barcode(二路动态规划)

    ACM思维题训练集合 Desciption You've got an n × m pixel picture. Each pixel can be white or black. Your task ...

  4. CF思维联系–CodeForces -224C - Bracket Sequence

    ACM思维题训练集合 A bracket sequence is a string, containing only characters "(", ")", ...

  5. CF思维联系–CodeForces - 222 C Reducing Fractions(数学+有技巧的枚举)

    ACM思维题训练集合 To confuse the opponents, the Galactic Empire represents fractions in an unusual format. ...

  6. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  7. 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 ...

  8. Codeforces 1106F Lunar New Year and a Recursive Sequence (数学、线性代数、线性递推、数论、BSGS、扩展欧几里得算法)

    哎呀大水题..我写了一个多小时..好没救啊.. 数论板子X合一? 注意: 本文中变量名称区分大小写. 题意: 给一个\(n\)阶递推序列\(f_k=\prod^{n}_{i=1} f_{k-i}b_i ...

  9. Codeforces Round #627 (Div. 3) E - Sleeping Schedule(递推)

    题意: 每天有 h 小时,有一序列 an,每次可以选择 ai 或 ai - 1 小时后睡觉,问从 0 次 0 时开始,最多在 l ~ r 时间段入睡多少次. 思路: 如果此时可达,计算此时可达的时间点 ...

随机推荐

  1. Vulnhub webdeveloper靶机渗透

    信息搜集 nmap -sP 192.168.146.0/24 #主机发现 nmap -A 192.168.146.148 #综合扫描 访问一下发现是wordpress,wp直接上wpscan wpsc ...

  2. 用最新的版本,蹦最野的迪~~~IDE写大数据程序避坑指南

    文章更新于:2020-04-05 注:本次实验使用的操作系统及各个程序版本号 类别 版本号 说明 操作系统 Ubuntu 16.04.6 LTS 代号 xenial jdk java version ...

  3. Django常用的第三方包

    Django常用的第三方包 API开发 djangorestframework django-rest-multiple-models django-cors-headers 查询 django-fi ...

  4. openlayers-统计图显示(中国区域高亮)

    openlayers版本: v3.19.1-dist 统计图效果:         案例下载地址:https://gitee.com/kawhileonardfans/openlayers-examp ...

  5. Java第十五天,泛型

    一.定义 泛型是一种未知的数据类型,即当我们不知道该使用哪种数据类型的时候,可以使用泛型. 泛型的本质是为了  参数化 类型(在不创建新的类型的情况下,通过泛型指定的不同类型来控制形参具体限制的类型) ...

  6. MODIS系列之NDVI(MOD13Q1)一:数据下载(一)基于插件

    引言: 写MODIS数据处理这个系列文章的初衷,主要是为了分享本人处理MODIS数据方面的一些经验.鉴于网上对这方面系统性的总结还比较少,我搜集资料时也是走了许多的弯路,因此希望通过此文让初学者能够更 ...

  7. 36 Thread 多线程

    /* * 多线程的实现方式: * 方式1:一种方法是将类声明为 Thread 的子类.该子类应重写 Thread 类的 run 方法.接下来可以分配并启动该子类的实例 * * Thread * Str ...

  8. C语言变长数组

    #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Variable ...

  9. AJ整理问题之:copy,对象自定义copy 什么是property

    AJ分享,必须精品 copy copy的正目的 copy 目的:建立一个副本,彼此修改,各不干扰 Copy(不可变)和MutableCopy(可变)针对Foundation框架的数据类型. 对于自定义 ...

  10. AJ学IOS(07)UI之UITextField代理事件_类似QQ登陆窗口的简单实现

    AJ分享,必须精品 先看效果图: 学习代码 // // NYViewController.m // 05-UITextField事件_UIKit复习 // // Created by apple on ...