【计数】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数组,找到最低点,然后再 ...
随机推荐
- Microsoft JDBC Driver 使用 getParameterMetaData 会报错?
不知道为何使用 Microsoft JDBC Driver for SQL Server 驱动时,sql语句不带参数没有问题,但是如果带参数且使用 getParameterMetaData 就会提示某 ...
- (六)Redis主从自动恢复-sentinel
原文地址,转载请注明出处: http://blog.csdn.net/qq_34021712/article/details/72026313 ©王赛超 准备工作:(1个master,2个sl ...
- TemplateBinding与Binding区别,以及WPF自定义控件开发的遭遇
在上一次的文章WPF OnApplyTemplate 不执行 或者执行滞后的疑惑谈到怎么正确的开发自定义控件,我们控件的样式中,属性的绑定一般都是用TemplateBinding来完成,如下一个基本的 ...
- concurrent.futures模块与协程
concurrent.futures —Launching parallel tasks concurrent.futures模块同时提供了进程池和线程池,它是将来的使用趋势,同样我们之前学习 ...
- Visual Studio Code的快捷键和相关技巧
编辑相关的键盘快捷键: Shift + Alt + F = 格式化代码(似乎不好用) Ctrl + Shift + Enter = 在上一行新建空行并转到上一行 Ctrl + K,Ctrl + C = ...
- Android ImageView的几种对图片的缩放处理 解决imageview放大图片后失真问题解决办法
我的解决办法: 1 首先设置android:layout_width=”wrap_content”和android:layout_height=”wrap_content”,否则你按比例缩放后的图片放 ...
- Linux、命令ps 各字段意思
参数: -A :所有的进程均显示出来,与 -e 具有同样的效用: -a : 显示现行终端机下的所有进程,包括其他用户的进程: -u :以用户为主的进程状态 : x :通常与 a 这个参数一起使用,可列 ...
- redis在Windows下以后台服务一键搭建集群(多机器)
redis在Windows下以后台服务一键搭建集群(多机器) 一.概述 此教程介绍如何在windows系统中多台机器之间布置redis集群,同时要以后台服务的模式运行.布置以脚本的形式,一键完成.多台 ...
- centos开机启动自定义脚本
有些时候我们需要在服务器里设置一个脚本,让他一开机就自己启动.方法如下: cd /etc/init.d vi youshell.sh #将youshell.sh修改为你自己的脚本名 编写自己的脚本后保 ...
- windows 10 开启安卓模拟器蓝屏
上周装了个vs2017 rc 本想试试 开发安卓怎么样,花了一晚上时间终于装好了. 第二天开夜神模拟器的时候蓝屏了.. 然后就逐个卸载VS2017的功能,先是卸了 自带的仿真程序,没用.然后全部卸载掉 ...