【计数】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数组,找到最低点,然后再 ...
随机推荐
- Django 03 模板路径、模板变量、常用的过滤器
Django 03 模板路径.模板变量.常用的过滤器 一.模板路径 #1.在每个app下面添加一个templates文件 #2.在项目views.py里面第33行INSTALLED_APPS里面添加上 ...
- PHPExcel探索之旅---阶段一
类似于Java,php也有操作Excel的方法,其中需要下载PHPExcel插件,将其中的Classes文件夹改名为PHPExcel并提取到根文件夹外面,将两个文件夹一起放在所需项目中 使用PHPEx ...
- (反NIM)
题目大意是和普通的NIM游戏一样,但是却是取到最后一个是输的,天真的以为就是反过来,其实并不是这样的 结论 先手必胜的条件为 ①:所有堆的石子数均=1,且有偶数堆. ②:至少有一个堆的石子数>1 ...
- 使用shell巧妙高效的批量删除历史文件或目录
背景:有实时产生的数据按小时分文件保存,如“/data/2013/09/18/14.txt”.现需要保留30天的最新数据,而删除所有其它的历史数据.注意“保留30天的最新数据”,可能不是连续的30天, ...
- springMvc配置 中文api
http://7xvpsh.com1.z0.glb.clouddn.com/publish/21-2/the-dispatcher-servlet.html springmvc4.1.7:配置 复制转 ...
- 新手常见Python运行时错误
经过整理与在实际中遇到的问题,将新手经常遇到的汇总下,以便自己犯傻又这么干了 1)"SyntaxError :invalid syntax",语法错误 A.查看是否在 if , e ...
- TortoiseSVN 控制图标未显示或显示异常解决方法
- Java 内存模型(零)
经典老图: 方法区和堆:由所有线程共享的数据区 虚拟机栈和本地方法栈和程序计数器:线程隔离的数据区 后面一步步讲这个图里面所涉及到的内容,待续...
- spring mvc 注解扫描问题 ,扫描不到controller, use-default-filters="false"
今天搭了个spring mvc项目,怎么也扫描不到controller,最后发现问题在use-default-filters="false"上面,乱copy出的问题 (默认值是tr ...
- JavaFX上手--第1天
1.第一个JavaFX Application JavaFX 使用Java来制作可视化图形,可以做动画和3D效果,JavaFX从JDK中直接使用. package application; impor ...