51nod 1161 Partial Sums
第1行,2个数N和K,中间用空格分隔,N表示数组的长度,K表示处理的次数(2 <= n <= 5000, 0 <= k <= 10^9, 0 <= a[i] <= 10^9)
共N行,每行一个数,对应经过K次处理后的结果。每次累加后mod 10^9 + 7。
4 2
1
3
5
6
1
5
14
29
————————————————————————
这题我们单独考虑矩阵乘法 我们发现 这个矩阵大概是长这样的
1 1 1 .... 1
0 1 1 ..... 1
0 0 1 ..... 1
0 0 0 ..... 1
然后观察发现 我们可以通过第一行直接推出下面的所有行
我们再考虑发现第一行每一位满足一定的条件
第i个=C(k+i-1,i-1)然后就可以nlogn+n^2直接推出最后的矩阵
然后在n^2矩阵乘法直接推出答案辣
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
const int M=5e3+,mod=1e9+;
int read(){
int ans=,f=,c=getchar();
while(c<''||c>''){if(c=='-') f=-; c=getchar();}
while(c>=''&&c<=''){ans=ans*+(c-''); c=getchar();}
return ans*f;
}
int n,k;
int s[M],ans[M];
int b[M][M];
LL inv(LL a,LL b){
LL ans=;
while(b){
if(b&) ans=ans*a%mod;
b>>=; a=a*a%mod;
}return ans;
}
int main(){
n=read(); k=read()-;
for(int i=;i<=n;i++) s[i]=read()%mod;
b[][]=; for(int i=;i<n;i++) b[][i+]=1LL*b[][i]*(k+i)%mod*inv(i,mod-)%mod;
//for(int i=1;i<=n;i++) printf("[%d] ",b[1][i]); puts("");
for(int i=;i<=n;i++){
int cnt=;
for(int j=i;j<=n;j++) b[i][j]=b[][++cnt];
}
// for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=n;j++) printf("[%d] ",b[i][j]);
for(int i=;i<=n;i++)for(int j=;j<=n;j++) ans[i]=(ans[i]+1LL*s[j]*b[j][i]%mod)%mod;
for(int i=;i<=n;i++) printf("%d\n",ans[i]);
return ;
}
51nod 1161 Partial Sums的更多相关文章
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- 51nod 1172 Partial Sums V2
题目 给出一个数组A,经过一次处理,生成一个数组S,数组S中的每个值相当于数组A的累加,比如:A = {1 3 5 6} => S = {1 4 9 15}.如果对生成的数组S再进行一次累加操作 ...
- 51nod 1172 Partial Sums V2 卡精度的任意模数FFT
卡精度的任意模数fft模板题……这道题随便写个表就能看出规律来(或者说考虑一下实际意义),反正拿到这题之后,很快就会发现他是任意模数fft模板题.然后我就去网上抄了一下板子……我打的是最土的任意模数f ...
- 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 ...
- 【计数】cf223C. Partial Sums
考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...
- CodeForces 223C Partial Sums 多次前缀和
Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...
随机推荐
- 第三章 ServerSpcket用法详解
构造ServerSocket ServerSocket的构造方法如下: ServerSocket() //Creates an unbound server socket. ServerSocket( ...
- Swift-属性监听
监听属性的改变(开发中使用很多) oc中长是重写set方法 swift通过属性监听器 class Dog: NSObject { var name:String?{ // 属性监听器 // 属性即将改 ...
- 《高性能JavaScript》学习笔记——日更中
------------------2016-7-20更------------------ 最近在看<高性能JavaScript>一书,里面当中,有讲很多提高js性能的书,正在看的过程中 ...
- Kettle 使用Json输入
import java.math.BigDecimal; private static final String JD="jd"; private static final Str ...
- apache server-status配置
引言 自己配置LAMP服务器时(xwamp),获取状态信息出现错误: You don't have permission to access /server-status on this server ...
- (转)Nginx图片服务器
本文转至博客http://wenxin2009.iteye.com/blog/2117079 Nginx搭建图片服务器 Nginx下载地址:http://nginx.org/en/download.h ...
- ubuntu16.04上安装配置DHCP服务的详细过程
DHCP服务器是为客户端机器分配IP地址的,所有分配的IP地址都保存在DHCP服务器的数据库中.为了在子网中实现DHCP分配IP地址,需要在目标主机上安装配置DHCP服务 1. 安装DHCP服务 安装 ...
- 学Python Django学得很迷茫,怎么办?-转自知乎
本人学生,零编程基础,在学习python的过程中越学越迷茫,感觉像无头苍蝇一样,来知乎取经,下面进入正题吧: 我是先看了中谷的python教学视频,然后跟着慕课网上的python教程把题 ...
- PHP 面试知识梳理
算法与数据结构 BTree和B+tree BTree B树是为了磁盘或者其他存储设备而设计的一种多叉平衡查找树,相对于二叉树,B树的每个内节点有多个分支,即多叉. 参考文章:https://www.j ...
- Android 通过浏览器打开应用
在很多应用的web站,其实都有这样一个功能,就是直接在网页中打开应用,接下来的就来探讨一下这个功能的实现,有些地方也我还没弄明白,还请懂的大神指点. 首先,得说一点不好消息,在微信中,这样的方式是行不 ...