zoukankan      html  css  js  c++  java
  • 51 Nod 1161 Partial sums

    1161 Partial Sums 

    题目来源: CodeForces

    基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题

     收藏

     取消关注

    给出一个数组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
    #include<bits/stdc++.h>
    #include<stdio.h>
    #include<iostream>
    #include<cmath>
    #include<math.h>
    #include<queue>
    #include<set>
    #include<map>
    #include<iomanip>
    #include<algorithm>
    #include<stack>
    #define inf 0x3f3f3f3f
    using namespace std;
    typedef long long ll;
    #define P 1000000007
    typedef long long LL;
    LL inv(LL t, LL p)
    {//求t关于p的逆元,注意:t要小于p,最好传参前先把t%p一下
        return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;
    }
    
    int a[5005];
    LL myC[5005];
    LL ans[5005];
    int main()
    {
        int n,k;
        cin>>n>>k;
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        myC[0]=1;int k2=k;
        for(int i=1;i<n;i++)
        {
            myC[i]=(1ll*k2*myC[i-1]%P)*inv(i%P,P)%P;
            k2++;
        }
    
        ll tmp;
        for(int i=0;i<n;i++)
        {
            tmp=0;
            for(int j=i;j>=0;j--)
            {
                tmp=(tmp+1ll*myC[j]*a[i-j]%P)%P;
            }
            ans[i]=tmp;
        }
        for(int i=0;i<n;i++)
            cout<<ans[i]<<endl;
        return 0;
    }
    
  • 相关阅读:
    第5周进度条
    《掌握需求过程》阅读笔记02
    第3周进度条
    《掌握需求过程》阅读笔记01
    问题账户需求分析
    2016年秋季个人阅读计划
    Arrays.sort解析
    算法排序
    Oracl Over函数
    Maven初步
  • 原文地址:https://www.cnblogs.com/linruier/p/9556908.html
Copyright © 2011-2022 走看看