Partial Sums

题解:

一个数列多次前缀和之后, 对于第i个数来说他的答案就是

for(int i = ; i <= n; ++i){
for(int j = ; j <= i; ++j){
b[i] = (b[i] + 1ll * a[j] * C(k-+j-i,j-i)) % mod;
}
}

唯一注意的就是这个k会到1e9。

观察可能,其实我们最多也就用了n个组合数, 并且这个C(n, m) 的 m 足够小。

所以我们可以根据定义先把这几个组合数先预处理出来。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e3 + ;
int n, k;
int a[N], b[N];
int inv[N];
int c[N];
void init(){
int MOD = mod;
inv[] = ;
for(int i = ; i < N; i ++){
inv[i] = (MOD - MOD / i) * 1ll * inv[MOD % i] % MOD;
}
c[] = ;
for(int i = ; i <= n; ++i){
c[i] = ;
int now = k + i - ;
for(int j = ; j <= i; ++j){
c[i] = 1ll * c[i] * now % mod * inv[j] % mod;
--now;
}
}
}
int main(){
scanf("%d%d", &n, &k);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
init();
if(k){
for(int i = ; i <= n; ++i){
for(int j = ; j <= i; ++j){
b[i] = (b[i] + 1ll * a[j] * c[i-j]) % mod;
}
}
for(int i = ; i <= n; ++i)
a[i] = b[i];
}
for(int i = ; i <= n; ++i){
printf("%d%c", a[i], " \n"[i==n]);
}
return ;
}

CodeForces 223C Partial Sums 多次前缀和的更多相关文章

  1. Codeforces 223C Partial Sums 数论+组合数学

    题意非常easy,求不是那么好求的,k非常大 要操作非常多次,所以不可能直接来的.印象中解决操作比較多无非线段树 循环节 矩阵 组合数等等吧,这道题目 也就仅仅能多画画什么 的了 就以第一个案例为主吧 ...

  2. 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 ...

  3. 51nod1161 Partial Sums

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

  4. Non-negative Partial Sums(单调队列)

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  5. 51 Nod 1161 Partial sums

    1161 Partial Sums  题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  取消关注 给出一个数组A,经过一次 ...

  6. [codeforces 509]C. Sums of Digits

    [codeforces 509]C. Sums of Digits 试题描述 Vasya had a strictly increasing sequence of positive integers ...

  7. CodeForces 816B Karen and Coffee(前缀和,大量查询)

    CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...

  8. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  9. TOJ 1721 Partial Sums

    Description Given a series of n numbers a1, a2, ..., an, the partial sum of the numbers is defined a ...

随机推荐

  1. 多线程编程(Linux C)

    多线程编程可以说每个程序员的基本功,同时也是开发中的难点之一,本文以Linux C为例,讲述了线程的创建及常用的几种线程同步的方式,最后对多线程编程进行了总结与思考并给出代码示例. 一.创建线程 多线 ...

  2. PID算法资料【视频+PDF介绍】

    最近一直有网友看到我的博客后,加我好友,问我能不能给发一些PID的资料,今天找了一些资料放到百度网盘上,给大家下载: 视频资料 链接:https://pan.baidu.com/s/12_IlLgBI ...

  3. l命令练习题1

    1.创建/guanli 目录,在/guanli下创建zonghe 和 jishu 两个目录(一条命令) [root@localhost ~]# mkdir -p /guanli/zonghe | mk ...

  4. Servlet生成验证码并进行账号密码和验证码的验证登陆!

    前言: 人不是生来就懂事的,在编程的世界也是一样,想想在大一的时候我还是那个连输出Hello World!都不会的小孩子是,现在我已经可以编出属于我自己的小程序了.编程其实并不可怕,可怕的是你不去编. ...

  5. 源码解读 Spring Boot Profiles

    前言 上文<一文掌握 Spring Boot Profiles> 是对 Spring Boot Profiles 的介绍和使用,因此本文将从源码角度探究 Spring Boot Profi ...

  6. Yii2 登录Model

    <?php namespace app\models; use Yii; class User extends \yii\db\ActiveRecord implements \yii\web\ ...

  7. LCA最近公共祖先---倍增法笔记

    先暂时把模板写出来,A几道题再来补充 此模板也是洛谷上的一道模板题 P3379 [模板]最近公共祖先(LCA) #pragma GCC optimize(2) //o2优化 #include < ...

  8. 性能测试学习第五天-----Jmeter测试脚本&基础元件使用

    JMeter简介:一个100%的纯Java桌面应用,由Apache组织的开放源代码项目,它是功能和性能测试的工具.具有高可扩展性.支持Web(HTTP/HTTPS).SOAP.FTP.JAVA等多种协 ...

  9. SpringMVC源码分析4:DispatcherServlet如何找到正确的Controller

    SpringMVC是目前主流的Web MVC框架之一.  我们使用浏览器通过地址 http://ip:port/contextPath/path进行访问,SpringMVC是如何得知用户到底是访问哪个 ...

  10. tf.nn.l2_loss()的用法

    https://blog.csdn.net/yangfengling1023/article/details/82910536