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. java中查询某个类已经创建了多少个对象了

    这个代码主要是使用类的静态字段和构造函数,可以跟踪某个类所创建对象的个数.请写一个类,在任何时候都可以向它查询“你已经创建了多少个对象? 主要是在构造函数中用到了静态数据,进行显示已经构造了多少个类对 ...

  2. problems

    exceptionUnable to connect to userservice.shanmaohuwai.com:80 . Error #0: stream_socket_client(): un ...

  3. 10-jmeter 测试soap协议v1.2版本请求

    1.因为jmeter安装了第三方插件jmeter-plugins-manager.jar之后(具体安装看之前文章),此时就可简单直接测试soap协议1.2版本的请求了 2. 3.进行运行线程就可实现了 ...

  4. CNVD

    漏洞编号 漏洞名称 漏洞积分 奖励时间 CNVD-2020-15798 中国平乐县委员会组织部网站管理系统登录存在弱口令漏洞 1.0 2020-03-09 09:58:46.0 CNVD-2020-1 ...

  5. Python——flask漏洞探究

    python的用途是真的多,就连网站也能做,这个有点像Java的Servlet flask基础 hello world 我们先从基础的开始,在网页上打出hello world,python代码如下: ...

  6. 【转】Centos7启动网卡(获取ip地址)

    这里之所以是查看下IP ,是我们后面要建一个Centos远程工具Xshell 连接Centos的时候,需要IP地址,所以我们这里先 学会查看虚拟机里的Centos7的IP地址 首先我们登录操作系统 用 ...

  7. 对于不平凡的我来说,从小我就在想为啥别人就什么都能拥有,而看看自己却什么都没有,对于原来的我就会抱怨爸妈怎么没有别人父母都能给自己想要的,可我从未想过父母的文化只有小学,其实父母内心也有太多的辛酸,所以我不甘愿如此,从此让我在大学里面直接选择一个让我巨大的转折————IT。

    对于不平凡的我来说,从小我就在想为啥别人就什么都能拥有,而看看自己却什么都没有,对于原来的我就会抱怨爸妈怎么没有别人父母都能给自己想要的,可我从未想过父母的文化只有小学,其实父母内心也有太多的辛酸,所 ...

  8. Map使用foreach遍历方式,Map获取第一个键值

    List<Map<String, Object>> mapList = new ArrayList<>();  for (Map.Entry<String,O ...

  9. 进程管理工具 Supervisor

    要想在终端后台常驻进程,首先想到的是在命令后加 & 符号,来达到隐藏程序在后台的目的,尽管看起来进程已经在后台运行了,实际上终端会话关闭时进程还是会被 kill 掉,这种问题一般是采用搭配 n ...

  10. Hbase的安装与基本操作

    简介: 1安装 HBase​   本节介绍HBase的安装方法,包括下载安装文件.配置环境变量.添加用户权限等. 1.1 下载安装文件   HBase是Hadoop生态系统中的一个组件,但是,Hado ...