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 ...
随机推荐
- C#高级编程 (第六版) 学习 第二章:C#基础
第二章 基础 1,helloworld示例: helloworld.cs using System; using System.Collections.Generic; using System.Li ...
- artdialog对话框 三种样式 网址:http://www.planeart.cn/demo/artDialog/_doc/labs.html
摇头效果 类似与wordpress登录失败后登录框可爱的左右晃动效果 // 2011-07-17 更新 artDialog.fn.shake = function (){ var style = th ...
- PHP创建对象的几种形式
创建对象的几种形式 class C1{ var $p1 = 1; //定义一个属性: } 形式1: $o1 = new C1(); //通过一个类,去new出一个对象 形式2: $o2 = new ...
- RAD Studio 10.3 Rio (BCB & Dephi) 发布啦
期盼已久的RAD Studio 10.3 Rio 终于发布了: 下载链接:http://altd.embarcadero.com/download/radstudio/10.3/delphicbui ...
- HBASE+Solr实现详单查询--转
原文地址:https://mp.weixin.qq.com/s?srcid=0831kfMZgtx1sQbzulgeIETs&scene=23&mid=2663994161&s ...
- 【Java】时间转json格式化
@DateTimeFormat(pattern="yyyy-MM-ddHH:mm:ss") @JsonFormat(pattern="yyyy-MM-ddHH: ...
- [cogs1065]绿豆蛙的归宿
1065. [Nescafe19] 绿豆蛙的归宿 [题目描述] 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K条离开该点的道路, ...
- 【hdu6072】Logical Chain
Kosaraju算法,然後bitset優化 主要是學習一下自寫bitset的姿勢 #include<cstring> #include<algorithm> #include& ...
- 使DIV相对窗口大小左右拖动始终水平居中
<!doctype html> <html> <head> <meta http-equiv="content-type" content ...
- 20165218 实验二 Java面向对象程序设计
实验二 Java面向对象程序设计 课程:java程序设计 姓名:赵冰雨 学号:20165218 指导教师:娄嘉鹏 实验日期:2018.4.16 实验密级:Java开发环境的熟悉 实验内容.步骤与体会: ...