开始想的是O(n2logk)的算法但是显然会tle。看了解题报告然后就打表找起规律来。嘛是组合数嘛。时间复杂度是O(nlogn+n2)的

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=5e3+5;
const int mod=1e9+7;
ll ans[nmax],a[nmax];
ll pow(ll x,int n){
ll res=x;--n;
while(n){
if(n&1) res=res*x%mod;
x=x*x%mod;n>>=1;
}
return res;
}
int main(){
int n=read(),m=read();--m;
ans[1]=1;
rep(i,2,n) ans[i]=ans[i-1]*(i+m-1)%mod*pow(i-1,mod-2)%mod;
ll tp,u;
rep(i,1,n) a[i]=read();
rep(i,1,n){
tp=0;
rep(j,1,i) tp=(tp+ans[j]*a[i-j+1])%mod;
printf("%lld\n",tp);
}
return 0;
}

  

题目来源: CodeForces
基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
 收藏
 关注
给出一个数组A,经过一次处理,生成一个数组S,数组S中的每个值相当于数组A的累加,比如:A = {1 3 5 6} => S = {1 4 9 15}。如果对生成的数组S再进行一次累加操作,{1 4 9 15} => {1 5 14 29},现在给出数组A,问进行K次操作后的结果。(每次累加后的结果 mod 10^9 + 7)

 
Input
第1行,2个数N和K,中间用空格分隔,N表示数组的长度,K表示处理的次数(2 <= n <= 5000, 0 <= k <= 10^9, 0 <= a[i] <= 10^9)
Output
共N行,每行一个数,对应经过K次处理后的结果。每次累加后mod 10^9 + 7。
Input示例
4 2
1
3
5
6
Output示例
1
5
14
29

51nod1161 Partial Sums的更多相关文章

  1. 题解 [51nod1161] Partial Sums

    题面 解析 我们设\(f[i]\)表示\(k\)次操作后第一个数在第\(i\)个位置上加了多少次, 而其它的数也可以类推, 第\(i\)个数在第\(j\)个位置加的次数就是\(f[j-i+1]\). ...

  2. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  3. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  4. TOJ 1721 Partial Sums

    Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...

  5. 【计数】cf223C. Partial Sums

    考试时候遇到这种题只会找规律 You've got an array a, consisting of n integers. The array elements are indexed from ...

  6. CodeForces 223C Partial Sums 多次前缀和

    Partial Sums 题解: 一个数列多次前缀和之后, 对于第i个数来说他的答案就是 ; i <= n; ++i){ ; j <= i; ++j){ b[i] = (b[i] + 1l ...

  7. 51 Nod 1161 Partial sums

    1161 Partial Sums  题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 给出一个数组A,经过一次 ...

  8. 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 ...

  9. hdu 4193 - Non-negative Partial Sums(滚动数列)

    题意: 给定一个由n个整数组成的整数序列,可以滚动,滚动的意思就是前面k个数放到序列末尾去.问有几种滚动方法使得前面任意个数的和>=0. 思路: 先根据原来的数列求sum数组,找到最低点,然后再 ...

随机推荐

  1. sql server 批量删除数据表

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Auth ...

  2. Sqli-labs less 58

    Less-58 执行sql语句后,并没有返回数据库当中的数据,所以我们这里不能使用union联合注入,这里使用报错注入. Payload:http://127.0.0.1/sqli-labs/Less ...

  3. CentOS 6下安装nginx

    原文:http://yubosun.akhtm.com/tech/centos-nginx.htm 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/dow ...

  4. swfObject 使用说明

    1.Embed your SWF with JavaScript 使用方法  swfobject.embedSWF(swfUrl, id, width, height, version, expres ...

  5. 我是如何学习 Linux 的

    为何要学习 Linux? 这个问题可能困扰着很多 Linux 初学者和爱好者,其实我也说不上来为何要学习 Linux,可能最实在的理由就是—-Linux 相关工作岗位很多.在“见到” Linux 的第 ...

  6. PHP组合模式

    一.组合模式简述 1.组合定义了一个单根继承体系,使具有不同职责的集合可以并肩工作 2.如果想像对待单个对象一样对待组合对象,那么组合模式十分有用 3.组合模式不能很好地在关系数据库中保存数据,但却非 ...

  7. QT中显示GIF图片

    在QT中要显示GIF图片,不能通过单单的添加部件来完成. 还需要手动的编写程序. 工具:QT Creator 新建一个工程,我们先在designer中,添加一个QLabel部件. 如下图: 将QLab ...

  8. Struts2笔记——与ServletAPI解耦

    与ServletAPI解耦的访问方式 为了避免与 Servlet API 耦合在一起, 方便 Action 做单元测试, Struts2 对 HttpServletRequest, HttpSessi ...

  9. SSIS ->> Reliability And Scalability

    Error outputs can obviously be used to improve reliability, but they also have an important part to ...

  10. org.opencv.android.JavaCameraView 摄像机方向的问题

    ——> org.opencv.android.JavaCameraView 摄像机方向的问题 ref: http://www.tuicool.com/articles/q6vUvqB 注意:一般 ...