开始想的是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. 100个经典的C算法

    1.题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔 子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数 为多少? #include<stdio.h&g ...

  2. 采用Asp.Net的Forms身份验证时,持久Cookie的过期时间会自动扩展

    原文:http://www.cnblogs.com/sanshi/archive/2012/06/22/2558476.html 若是持久Cookie,Cookie的有效期Expiration属性有当 ...

  3. POJ 1222

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6196   Accepted: 40 ...

  4. c#知识库同步的总结

    C#知识库下载地址: http://www.51aspx.com/Code/FileCollector 新版下载地址:http://pan.baidu.com/s/1P3Hk 对于这一款平时用来收集知 ...

  5. LoaderManager使用详解(二)---了解LoaderManager

    了解LoaderManager   这篇文章将介绍LoaderManager类,这是该系列的第二篇文章. 一:Loaders之前世界 二:了解LoaderManager 三:实现Loaders 四:实 ...

  6. 历代诗词咏宁夏注释2_----苍岩道人<登文昌阁>

    登文昌阁[1] 苍岩道人 壮年碌碌走尘埃,此地清幽不肯来. 老去始惊春梦促,韶光易过槿花开.[2] 历朝兴废书千卷,万古忠奸土一堆.[3] 惟爱莎罗歌最好,闲时拍板满斟杯.[4] 注释 [说明]选自& ...

  7. PHP 判断是否包含某字符串

    PHP语言是一个功能强大的嵌入式HTML脚本语言,它的易用性让许多程序员选择使用.PHP判断字符串的包含,可以使用PHP的内置函数 strstr,strpos,stristr直接进行判断.也可以通过e ...

  8. 饶有兴致的用javascript做了个贪食蛇游戏

    09年写的东西.一直藏在自己的记事本里头,现在开始整理写博客,所以直接搬过来 先上效果图 再添代码: <HTML> <HEAD> <TITLE>贪吃蛇 Snake ...

  9. Appium入门示例(python)

    安装Python依赖 pip3.4 install nose pip3.4 install selenium pip3.4 install Appium-Python-Client 运行测试用例and ...

  10. MongoDB (六) MongoDB 集合操作

    一. MongoDB 创建集合 createCollection() 方法 MongoDB db.createCollection(name, options) 是用来创建集合. 语法: 基本的 cr ...