题解 [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) ...
随机推荐
- Guava 工具类之Strings 的使用
public class StringTest { public static void main(String[] args) { //判断是null还是空字符串 boolean b1 = Stri ...
- Feign 接口上传文件
1)Encoder 配置注入容器 2) public class SpringFormEncoderExtension extends FormEncoder { /** * 使用默认的feign编码 ...
- Python 解leetcode:49. Group Anagrams
题目描述:给出一个由字符串组成的数组,把数组中字符串的组成字母相同的部分放在一个数组中,并把组合后的数组输出: 思路: 使用一个字典,键为数组中字符串排序后的部分,值为排序后相同的字符串组成的列表: ...
- Unable to find optional library: org.apache.http.legacy 错误
在目录adt-bundle-windows-x86_64-20140702\sdk\platforms\android-20或者 C:\Users\Administrator\AppData\Loca ...
- Ubuntu 安装 QtCreator (version : Qt 5.9.8)
平台 :Ubuntu 16.04 QT :5.9.8 (open source) 首先去QT安装包下载安装包,为了保持与arm板子的统一,本人选择了 5.9.8 版本的QT 可 ...
- HTTP协议探究(四):TCP和TLS优化
一 复习与目标 1 复习 简单密码学.对称加密与非对称加密 数字签名.数字证书 SSL/TLS HTTPS = HTTP + SSL/TLS,SSL/TLS为HTTP提供了保密性.完整性和鉴别性 2 ...
- 关于spring中事务管理的几件小事
1.Spring中的事务管理 作为企业级应用程序框架,Spring在不同的事务管理API之上定义了一个抽象层.而应用程序开发人员不必了解底层的事务管理API,就可以使用Spring的事务管理机制. S ...
- 本地存储和vuex使用对比
1. sessionStorage sessionStorage 方法针对一个 session 进行数据存储.当用户关闭浏览器窗口后,数据会被删除. 用法: 储存: 1. 点(.)运算符 ...
- 页面加载完毕后调用js方法进行布局操控 已实验
页面加载完毕后调用js方法进行布局操控 已实验 $(function(){ var check1 = $("[id$=SMS]").is(':checked'); var bl=$ ...
- vue+element-ui 项目中实现复制文字链接功能
需求: 点击复制按钮,复制一个链接 在GitHub上找到一个clipboard组件,功能比较齐全 使用方法: 安装 npm i clipboard --save HTML <template ...