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

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. 6、kvm克隆虚拟机

    kvm克隆有两种方法可以使用先暂停kvm虚拟机 virsh suspend privi-server 方法一:对虚拟机本身直接clone virt-clone -o privi-server -n p ...

  2. htmlunit最具有参考意义项目

    ### HtmlUnit What? - 项目1 https://gitee.com/dgwcode/spiderTmallTradeInfo - 项目2 https://gitee.com/dgwc ...

  3. 08-图8 How Long Does It Take (25 分

    Given the relations of all the activities of a project, you are supposed to find the earliest comple ...

  4. jap的教程

    第一个资料:   https://wenku.baidu.com/view/5ca6ce6a1eb91a37f1115cee.html 第二个资料 :http://www.yiibai.com/jpa ...

  5. 020 Valid Parentheses 有效的括号

    给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效.括号必须以正确的顺序关闭,"()" 和 "()[]{}" 是有效的 ...

  6. (转)CentOS 7常见的基础命令和配置

    CentOS 7常见的基础命令和配置 原文:http://blog.51cto.com/hujiangtao/1973566 管理服务 命令格式:systemctl COMMAND name.serv ...

  7. python接口自动化(四十一)- 发xml格式参数的post请求(超详解)

    简介 最近在工作中,遇到一种奇葩的接口,它的参数数据是通过xml,进行传递的,不要大惊小怪的,林子大了什么鸟都有,每个人的思路想法不一样,开发的接口也是各式各样的,如果想要统一的话,必须是提前团队已经 ...

  8. Navicat for mysql远程连接数据库详解(1130错误解决方法)

    用Navicat for mysql连接数据库测试下连接 如果出现1130错误 错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to ...

  9. 经典SQL语句集锦(收藏版)

    文章来源:http://www.cnblogs.com/herbert/archive/2010/07/02/1770062.html SQL分类: DDL—数据定义语言(CREATE,ALTER,D ...

  10. ElasticSearch java API 按照某个字段排序

    searchRequestBuilder.addSort("publish_time", SortOrder.DESC); 按照某个字段排序的话,hit.getScore()将会失 ...