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 ...
随机推荐
- [二叉查找树] 1115. Counting Nodes in a BST (30)
1115. Counting Nodes in a BST (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- Qt多线程-QtConcurrent并行运算高级API
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QtConcurrent并行运算高级API 本文地址:http://tec ...
- [转帖]Linux 的UTC 和 GMT
1.问题 对于装有Windows和Linux系统的机器,进入Windows显示的时间和Linux不一致,Linux中的时间比Windows提前8个小时. 2.解决方法 修改/etc/default/r ...
- error CS0234: 命名空间“System.Drawing”中不存在类型或命名空间名称“Image”(是否缺少程序集引用?)
- hibernate.cfg.xml案例
一.概念. hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,使得Java程序员可以随心所欲的使用对象编程思维来操纵数据库.既然学习Hibernate那么第 ...
- 如何让TEdit在获取输入焦点后selectAll?
关于网友提出的“ 如何让TEdit在获取输入焦点后selectAll?”问题疑问,本网通过在网上对“ 如何让TEdit在获取输入焦点后selectAll?”有关的相关答案进行了整理,供用户进行参考,详 ...
- 数据库引擎InnoDB和MyISAM区别
MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Method:有索引的顺序访问方法)所改良.虽然性能极佳,但却有一个缺点 ...
- DataTable Excel 导出:
public static class CSVFileHelper { public static string ToHtmlTable(this DataTable target) { return ...
- 【bzoj1495】[NOI2006]网络收费 暴力+树形背包dp
题目描述 给出一个有 $2^n$ 个叶子节点的完全二叉树.每个叶子节点可以选择黑白两种颜色. 对于每个非叶子节点左子树中的叶子节点 $i$ 和右子树中的叶子节点 $j$ :如果 $i$ 和 $j$ 的 ...
- ES2015中let的暂时性死区(TDZ)
Tomporal Dead Zone (TDZ)是ES2015中对作用域新的专用定义.是对于某些遇到在区块作用域绑定早于声明语句时的情况.Tomporal Dead Zone (TDZ)可以理解为时间 ...