考试时候遇到这种题只会找规律

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:

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


题目分析

可以从矩阵乘法开始想起,考虑转移矩阵,发现其主对角线下方全为0、元素按照次对角线对称。

或者就是找规律

3.16upd:

总觉得一个经典模型不应该用找规律这么假的方式随随便便搞掉吧……

网上的题解都是打表找规律 | 矩乘找规律 | dp找规律……

来自ZZK的新的理解方式:$a_i$的贡献也就是它走到$s^p_j$的方案数量。

 #include<bits/stdc++.h>
#define MO 1000000007
const int maxn = ; int n,k,a[maxn],b[maxn],inv[maxn],fac[maxn],pre[maxn]; void init()
{
fac[] = fac[] = inv[] = inv[] = ;
for (int i=; i<=n; i++)
fac[i] = 1ll*fac[i-]*i%MO,
inv[i] = MO-1ll*(MO/i)*inv[MO%i]%MO;
pre[] = ;
for (int i=; i<=n; i++)
pre[i] = 1ll*pre[i-]*(k%MO+i-)%MO*inv[i]%MO;
}
int main()
{
scanf("%d%d",&n,&k);
for (int i=; i<=n; i++) scanf("%d",&a[i]), b[i] = a[i];
if (k){
init();
for (int i=; i<=n; i++)
{
b[i] = ;
for (int j=; j<=i; j++)
b[i] = 1ll*(b[i]+1ll*pre[i-j]*a[j]%MO)%MO;
}
}
for (int i=; i<=n; i++) printf("%d ",b[i]);
return ;
}

END

【计数】cf223C. Partial Sums的更多相关文章

  1. 51nod1161 Partial Sums

    开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...

  2. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. TOJ 1721 Partial Sums

    Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...

  5. CodeForces 223C Partial Sums 多次前缀和

    Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...

  6. 51 Nod 1161 Partial sums

    1161 Partial Sums  题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 给出一个数组A,经过一次 ...

  7. CF思维联系–CodeForces - 223 C Partial Sums(组合数学的先线性递推)

    ACM思维题训练集合 You've got an array a, consisting of n integers. The array elements are indexed from 1 to ...

  8. CF223C【Partial Sums】(组合数学+乱搞)

    题面 传送门 题解 orz zzk 考虑这东西的组合意义 (图片来自zzk) \(a_i\)这个元素对\(k\)阶前缀和的第\(j\)个元素\(s_{k,j}\)的贡献就等于从\((0,i)\)走到\ ...

  9. hdu 4193 - Non-negative Partial Sums(滚动数列)

    题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...

随机推荐

  1. DB2 触发器使用1

    本文基于多篇博文整理而来,目的是较全面的学会使用DB2触发器,后期再整理复杂的使用场景,看完本文应该能够自己创建一个基本的触发器. 1.什么是触发器当一个指定的 SQL 操作(如 DELETE,INS ...

  2. jquery——动画

    1.通过animate方法可以设置元素某属性值上的动画 <!DOCTYPE html> <html lang="en"> <head> < ...

  3. vector的学习(系统的学习)

    首先讲一下vector,vector被称作向量容器,头文件要包括#include<vector> 可以考虑下面定义: vector<int> x; vector<char ...

  4. Java local 转UTC时间

    import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; impor ...

  5. Storm概念学习系列之storm的设计思想

    不多说,直接上干货! storm的设计思想 在 Storm 中也有对流(Stream)的抽象,流是一个不间断的.无界的连续 Tuple(Storm在建模事件流时,把流中的事件抽象为 Tuple 即元组 ...

  6. JavaScript 系列--JavaScript一些奇淫技巧的实现方法(一)简短的sleep函数,获取时间戳

    一.前言 有些东西很好用,但是你未必知道:有些东西你可能用过,但是你未必知道原理.实现一个目的有多种途径,俗话说,条条大路通罗马.发散一下大家的思维以及拓展一下知识面. 二.实现一个简短的sleep函 ...

  7. 【Linux】让Ubuntu 支持 GBK等字符集,解决中文乱码

    对GBK,GB2312,GB18030字符集的支持是UBUNTU中文乱码的罪魁祸首,其实我们可以在保持UTF-8为默认编码的条件下添加对这几个编码的支持,以解决中文乱码问题. 我想这个问题肯定有其他人 ...

  8. *.rpm is not signed解决

    1.# yum install qemu*报错如下:Package qemu-kvm-tools-0.12.1.2-2.113.el6.x86_64.rpm is not signed2.解决# vi ...

  9. 从零开始的全栈工程师——js篇2.16

    js操作css样式 div.style.width=“200px” 在div标签内我们添加了一个style属性 并设定了width值 这种写法会给标签带来了大量的style属性 跟实际项目是不符的 我 ...

  10. Maven下 SpringMvn+thymeleaf 搭建

    1.首先新建一个项目 2.根据以下选项,点击下一步 3.随便输入 4.配置maven的路径 5.点击完成 6.等待所有maven的库文件下载完成后配置pom.xml依赖 <dependency& ...