题面

解析

我们设\(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. bat命令教程

    转自:https://www.jb51.net/article/151923.htm 第一章 批处理基础 第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合 ...

  2. java http接口请求响应 request response

    接口类: 1 package org.sunshine.dcda.epg.wechat.controller.niao; 2 3 import javax.servlet.http.HttpServl ...

  3. MongoDB数据库、集合、文档的操作

    MongoDB系列第一课:MongDB简介 MongoDB系列第二课:MongDB环境搭建 MongoDB系列第三课:MongDB用户管理 MongoDB系列第四课:MongoDB数据库.集合.文档的 ...

  4. Promise.all的使用

    我有一个需求如下: 有一个学生号的数组,根据这个数组,取出相关学生的所有信息.获取学生信息的接口用setTime模拟,假设每次请求需要耗时2s,代码如下 // 获取学生信息接口 function ge ...

  5. bzoj 2734 集合悬殊 (状压dp)

    大意: 给定$n$, 求集合{1,2,...n}的子集数, 满足若$x$在子集内, 则$2x,3x$不在子集内. 记$f(x)$为$x$除去所有因子2,3后的数, 那么对于所有$f$值相同的数可以划分 ...

  6. WebStorm使用码云插件问题

    由于项目需求,需要在WebStorm中使用码云插件,在下载安装的过程中出现一系列的问题,现总结出现的问题和解决方法. 先说一下码云是什么?码云有什么作用? 码云的主要功能: 码云除了提供最基础的 Gi ...

  7. Javascript中的继承与复用

    实现代码复用的方法包括:工厂模式.构造函数模式.原型模式(<高三>6.2章 P144),它们各自的特点归结如下:1.工厂模式虽然使创建对象一定程度上实现了代码复用,但却没有解决对象识别问题 ...

  8. zepto学习(一)之click事件和tap事件比较

    一.click 和 tap 比较 两者都会在点击时触发,但是在手机WEB端,click会有 200~300 ms,所以请用tap代替click作为点击事件. singleTap和doubleTap分别 ...

  9. springboot 集成 dubbo(一)简介

    一.简介 1,springboot 是 一款快速开发的框架,减少了开发人员对配置文件的操作.采用一些注解来取代xml配置文件. 注解包含预先封装的注解和开发人员自定义注解.同时使用Maven.Grad ...

  10. 关于Mybatis的几件小事(一)

    一.Mybatis简介 1.Mybatis简介 MyBatis是支持定制化SQL.存储过程以及高级映射的优秀的持久层框架. MyBatis避免了几乎所有的JDBC代码和手动设置参数以及获取结果集. M ...