题面

解析

我们设\(f[i]\)表示\(k\)次操作后第一个数在第\(i\)个位置上加了多少次,

而其它的数也可以类推,

第\(i\)个数在第\(j\)个位置加的次数就是\(f[j-i+1]\).

通过找规律手玩样例后可以发现,

\(f[i]=C_{i+k-2}^{i-1}\).

(然而并不知道为什么)

最后对每个位置统计贡献就行了.

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std; inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
} const int N=5005;
int Mod=1000000007;
int n,K,a[N],f[N];
int jc[N]={1}; inline int fpow(int a,int b){
int ret=1;
while(b){
if(b&1) ret=ret*a%Mod;
a=a*a%Mod;b>>=1;
}
return ret;
} inline int inv(int x){
return fpow(x,Mod-2);
} inline int C(int n,int m){
int ret=1;
for(int i=n-m+1;i<=n;i++) ret=ret*i%Mod;
return ret*inv(jc[m])%Mod;
} signed main(){
n=read();K=read();
for(int i=1;i<=n;i++) jc[i]=jc[i-1]*i%Mod;
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=n;i++) f[i]=C(i+K-2,i-1);
for(int i=1;i<=n;i++){
int ret=0;
for(int j=1;j<=i;j++){
ret=(ret+a[j]*f[i-j+1]%Mod)%Mod;
}
printf("%lld\n",ret);
}
return 0;
}

题解 [51nod1161] Partial Sums的更多相关文章

  1. 51nod1161 Partial Sums

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

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

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

  3. 【计数】cf223C. Partial Sums

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

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

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

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

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

  6. TOJ 1721 Partial Sums

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

  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(想法题,单调队列)

    HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn) ...

随机推荐

  1. [转帖]Kubernetes中安装Helm及使用

    Kubernetes中安装Helm及使用 2018年07月02日 17:41:09 灬勿忘丶心安 阅读数 3699更多 分类专栏: K8S   版权声明:本文为博主原创文章,遵循CC 4.0 BY-S ...

  2. K60工程

    使用arm-none-eabi-objcopy工具将elf文件转换为hex文件 "D:/ELF/arm-none-eabi-objcopy.exe" -O ihex "D ...

  3. Python list,tuple,dict,set高级变量常用方法

    list列表 增加 append 在列表中追加,一次只能加一个 insert 按索引插入,一次只能插一个 extend 迭代追加到列表中 list1 = [1, 2, 3] list2 = [4, 5 ...

  4. springcloud注解

    @EnableEurekaServer:启动一个服务注册中心提供给其他应用进行对话 @EnableZuulProxy:开启网关; @FeignClient:发现服务 @EnableFeignClien ...

  5. vue开发环境配置跨域,一步到位

    本文要实现的是:使用vue-cli搭建的项目在开发时配置跨域,上线后不做任何任何修改,接口也可以访问,前端跨域解决方案 production:产品 生产环境 development:开发 开发环境 1 ...

  6. request.getScheme() 使用方法(转)

    今天在看代码时,发现程序使用了 request.getScheme() .不明白是什么意思,查了一下.结果整理如下: 1.request.getScheme() 返回当前链接使用的协议:一般应用返回h ...

  7. AngularJS-01.AngularJS,Module,Controller,scope

    1.AngularJS 一个构建动态Web应用程序的结构化框架. 基于JavaScript的MVC框架.(  MVC ---- Model(模型).View(视图).Controller(控制器) ) ...

  8. 5.API详解

    Dao 中需要通过 SqlSession 对象来操作 DB.而 SqlSession 对象的创建, 需要其工厂对象 SqlSessionFactory.SqlSessionFactory 对象, 需要 ...

  9. Heap(堆)与Stack(栈)的区别详解

    在了解堆与栈之前,我们想来了解下程序的内存分配 一个编译的程序占用的内存分为以下几个部分  :  1.栈区(stack)—   由编译器自动分配释放   ,存放函数的参数值,局部变量的值等.其    ...

  10. 【python+beautifulsoup4】Beautifulsoup4

    Beautiful soup将复杂HTML文档转换成一个复杂的属性结构,每个节点都是python对象,所有对象可归纳为4种Tag,NavigableString,BeautifulSoup,Comme ...