首页 技术 正文
技术 2022年11月21日
0 收藏 832 点赞 4,365 浏览 1140 个字

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

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=5e3+5;
const int mod=1e9+7;
ll ans[nmax],a[nmax];
ll pow(ll x,int n){
ll res=x;--n;
while(n){
if(n&1) res=res*x%mod;
x=x*x%mod;n>>=1;
}
return res;
}
int main(){
int n=read(),m=read();--m;
ans[1]=1;
rep(i,2,n) ans[i]=ans[i-1]*(i+m-1)%mod*pow(i-1,mod-2)%mod;
ll tp,u;
rep(i,1,n) a[i]=read();
rep(i,1,n){
tp=0;
rep(j,1,i) tp=(tp+ans[j]*a[i-j+1])%mod;
printf("%lld\n",tp);
}
return 0;
}

  

1161 Partial Sums51nod1161 Partial Sums题目来源: CodeForces基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题51nod1161 Partial Sums 收藏51nod1161 Partial Sums 关注给出一个数组A,经过一次处理,生成一个数组S,数组S中的每个值相当于数组A的累加,比如:A = {1 3 5 6} => S = {1 4 9 15}。如果对生成的数组S再进行一次累加操作,{1 4 9 15} => {1 5 14 29},现在给出数组A,问进行K次操作后的结果。(每次累加后的结果 mod 10^9 + 7)

 Input

第1行,2个数N和K,中间用空格分隔,N表示数组的长度,K表示处理的次数(2 <= n <= 5000, 0 <= k <= 10^9, 0 <= a[i] <= 10^9)

Output

共N行,每行一个数,对应经过K次处理后的结果。每次累加后mod 10^9 + 7。

Input示例

4 2
1
3
5
6

Output示例

1
5
14
29
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,994
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,507
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,350
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,135
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,768
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,845