题解 [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) ...
随机推荐
- Hanlp-地名识别调试方法详解
HanLP收词特别是实体比较多,因此特别容易造成误识别.下边举几个地名误识别的例子,需要指出的是,后边的机构名识别也以地名识别为基础,因此,如果地名识别不准确,也会导致机构名识别不准确. 类型1 数字 ...
- pandas合并excel文件
现在有多个excel 文件,需要对其进行合并 import pandas as pd path='' list1=[] #save data data=pd.read_excel(path,dtype ...
- Dom4j 生成xml并格式化
Document document = DocumentHelper.createDocument(); //创建root Element root = document.addEle ...
- 剑指offer29:最小的k个数
1 题目描述 输入n个整数,找出其中最小的K个数.例如输入4,5,1,6,2,7,3,8这8个数字,则最小的4个数字是1,2,3,4,. 2 思路和方法,C++核心代码 2.1 sort()函数,ve ...
- 微信小程序点击图片预览-wx.previewImage
<view class='imgList'> <view class='imgList-li' wx:for='{{imgArr}}'> <image class='im ...
- mysql中binglog底层原理分析
binglog 是一个二进制的日志文件,会记录mysql的数据更新或潜在个跟新 (delete from table where id =xxx) 主从复制就是依靠binglog master -sl ...
- 如何在调用Marketing Cloud contact创建API时增加对扩展字段的支持
需求:扩展字段"微信ID"是我创建出来的extension field,我想用Marketing Cloud提供的contact creation API,在创建contact时也 ...
- Spring Data JPA引入和介绍
第1章 1.ORM概述[了解] ORM(Object-Relational Mapping) 表示对象关系映射.在面向对象的软件开发中,通过ORM,就可以把对象映射到关系型数据库中.只要有一套程序能 ...
- css 之calc无效踩坑
踩坑: 1. height:calc(100vh-60); 无效 2.height:calc(100vh-60px); 无效 3.height:calc(100vh - 60px); 终于起效 总 ...
- STM32写选项字节(option bytes)的正确姿势
STM32 的 Flash information block 部分,包含有特殊的选项字节,可以用于系统配置等信息, 其中还有两个有效字节(实际四个字节,两个是校验字节)的用户自定义数据字节. 在尝试 ...