【计数】cf223C. 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.
题目分析
可以从矩阵乘法开始想起,考虑转移矩阵,发现其主对角线下方全为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的更多相关文章
- 51nod1161 Partial Sums
开始想的是O(n2logk)的算法但是显然会tle.看了解题报告然后就打表找起规律来.嘛是组合数嘛.时间复杂度是O(nlogn+n2)的 #include<cstdio> #include ...
- Non-negative Partial Sums(单调队列)
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 4193 Non-negative Partial Sums 单调队列。
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- TOJ 1721 Partial Sums
Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- 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 ...
- CF223C【Partial Sums】(组合数学+乱搞)
题面 传送门 题解 orz zzk 考虑这东西的组合意义 (图片来自zzk) \(a_i\)这个元素对\(k\)阶前缀和的第\(j\)个元素\(s_{k,j}\)的贡献就等于从\((0,i)\)走到\ ...
- hdu 4193 - Non-negative Partial Sums(滚动数列)
题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...
随机推荐
- Scala_Load csv data to hive via spark2.1
code: package com.liupu import org.apache.spark.{ SparkContext, SparkConf } import org.apache.spark. ...
- mybatis批量处理sql
转载大神 https://www.cnblogs.com/xujingyang/p/8301130.html
- 强制更新客户端Silverlight XAP 文件
在发布小程序更新的时候访问的总是原来的程序,猜想应该是缓存的原因.在网上查找方法 <div id="silverlightControlHost"> <objec ...
- windows 7 elasticsearch-5.3.2
# windows elasticsearch- D:\nescafe\elasticsearch-\bin λ java -version java version "1.8.0_121& ...
- DM设备的创建与管理
DM(Device Mapper)即设备映射(逻辑设备). MD和DM是Linux内核上2种工作机制(实现逻辑设备)不同的模块. Physical Volume(PV): 物理卷 底层 ...
- 牛客网Java刷题知识点之基本类型、引用类型
不多说,直接上干货! byte-short-int-long,方便识记.
- android 开发-数据存储之文件存储
android的文件存储是通过android的文件系统对数据进行临时的保存操作,并不是持久化数据,例如网络上下载某些图片.音频.视频文件等.如缓存文件将会在清理应用缓存的时候被清除,或者是应用卸载的时 ...
- js或者jq判断一段文字中是否有自己想要的那几个字,如果有就把那几个字变成红色
如何判断一段文字中是否有自己想要的那几个字,如果有就把那几个字变成红色(在html中)比如有body中有这么一串文字“驾驶的后视镜的华盛顿”,想要判断里面是否有“驾驶”这两个字,如果有就把这两个字变成 ...
- 【Android开发笔记】程序崩溃异常总结
广播注册相关(broadcastReceiver) 没有注册广播就注销广播 注册广播但未注销广播 注册广播后重复注销广播 解决办法: 添加一个布尔变量,注册广播后为true,若为true在执行注销,注 ...
- shell实现网站备份
#!/bin/bash ##back web directory scripts #需要备份的目录写入与脚本同级目录test.txt文件中 DIR="/data/server/www&quo ...