题解 [51nod1161] Partial Sums
解析
我们设\(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的更多相关文章
- 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 ...
- 【计数】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 ...
- 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 ...
- 51 Nod 1161 Partial sums
1161 Partial Sums 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 收藏 取消关注 给出一个数组A,经过一次 ...
- 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 ...
- HDU 4193 Non-negative Partial Sums(想法题,单调队列)
HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn) ...
随机推荐
- Java模版引擎之Freemarker
Java模版引擎之Freemarker freemarker是一款模版引擎,是一种基于模版生成静态文件的通用工具,它是为Java程序员提供的一个类库,它不是面向最终用户的,而是为程序员提供了一款可以嵌 ...
- Hadoop学习(4)-mapreduce的一些注意事项
关于mapreduce的一些注意细节 如果把mapreduce程序打包放到了liux下去运行, 命令java –cp xxx.jar 主类名 如果报错了,说明是缺少相关的依赖jar包 用命令had ...
- 超简单的js实现提示效果弹出以及延迟隐藏的功能
自动登录勾选提示效果 要求:鼠标移入显示提示信息框:鼠标离开,信息框消失,消失的效果延迟 <!DOCTYPE html> <html lang="en"> ...
- Do Not Try This Problem(分块思想)
题意:https://codeforces.com/group/ikIh7rsWAl/contest/259944/problem/D 给你q个操作,4个数n,a,k,c,从n好位置开始每次加a的位置 ...
- Python基础总结之第六天开始【先简单认识一次函数】(新手可相互督促)
午休后,看看电视,在回顾下新的知识----函数.相信很多小伙伴在学习python后 ,学到函数就会有一部分人放弃了,从努力到放弃(内容过于真实) 好希望我也能有很多粉丝,hhh.... 函数: 什么是 ...
- nginx核心模块常用指令
默认启动Nginx时,使用的配置文件是: 安装路径/conf/nginx.conf 文件,可以在启动nginx的时候,通过-c来指定要读取的配置文件 常见的配置文件有如下几个: nginx.conf: ...
- ActiveMQ入门系列三:发布/订阅模式
在上一篇<ActiveMQ入门系列二:入门代码实例(点对点模式)>中提到了ActiveMQ中的两种模式:点对点模式(PTP)和发布/订阅模式(Pub & Sub),详细介绍了点对点 ...
- python 获取导入模块的文件路径
接触到项目上有人写好的模块进行了导入,想查看模块的具体内容是如何实现的,需要找到模块的源文件. 本博文介绍两种查找模块文件路径方法: 方法一: #!/usr/bin/python # -*- codi ...
- .net 调用 winapi获取窗口句柄和内容
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 如何入门Pytorch之二:如何搭建实用神经网络
上一节中,我们介绍了Pytorch的基本知识,如数据格式,梯度,损失等内容. 在本节中,我们将介绍如何使用Pytorch来搭建一个经典的分类神经网络. 搭建一个神经网络并训练,大致有这么四个部分: 1 ...