给定长度为n的数组a,定义一次操作为:
1. 算出长度为n的数组s,使得si= (a[1] + a[2] + ... + a[i]) mod 1,000,000,007;
2. 执行a = s;
现在问k次操作以后a长什么样

记初始序列为$a_0$, $k$次操作后序列为$a_k$, 有

$\begin{equation}
a_k
=\begin{bmatrix}
1 & 0 & 0 &\cdots\ &0 &0\\
1 & 1 & 0 &\cdots\ &0 &0\\
1 & 1 & 1 & \cdots\ & 0 & 0\\
\vdots & \vdots & \vdots & \ddots & \vdots &\vdots\\
1 & 1 & 1 &\cdots\ &1& 1\\
\end{bmatrix}^k a_0
\end{equation}$

矩阵幂可以化简为

$\begin{equation}
\begin{bmatrix}
\binom{k-1}{0} & 0 & 0 &\cdots\ &0 &0\\
\binom{k}{1} & \binom{k-1}{0} & 0 &\cdots\ &0 &0\\
\binom{k+1}{2} & \binom{k}{1} &\binom{k-1}{0} & \cdots\ & 0 & 0\\
\vdots & \vdots & \vdots & \ddots & \vdots &\vdots\\
\binom{k+n-2}{n-1} & \binom{k+n-3}{n-2} & \binom{k+n-4}{n-3} &\cdots\ &\binom{k}{1}& \binom{k-1}{0}\\
\end{bmatrix}
\end{equation}$

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 2e3+10;
int n, k;
int a[N], f[N]; int main() {
scanf("%d%d", &n, &k);
REP(i,1,n) scanf("%d", a+i);
f[1] = 1;
REP(i,2,n) f[i]=(ll)f[i-1]*(k+i-2)%P*inv(i-1)%P;
REP(i,1,n) {
int ans = 0;
REP(j,1,i) ans = (ans+(ll)f[i-j+1]*a[j])%P;
printf("%d ", ans);
} hr;
}

牛客 109 C 操作数 (组合数学)的更多相关文章

  1. 牛客 197C 期望操作数

    大意: 给定$x,q$, 每步操作$x$等概率变为$[x,q]$中任意一个数, 求变为$q$的期望操作数. 很容易可以得到$f(x,q)=\frac{\sum\limits_{i=x+1}^qf(i, ...

  2. 牛客国庆集训派对Day4 I-连通块计数(思维,组合数学)

    链接:https://www.nowcoder.com/acm/contest/204/I 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1048576K,其他语言20 ...

  3. 牛客网 暑期ACM多校训练营(第一场)A.Monotonic Matrix-矩阵转化为格子路径的非降路径计数,Lindström-Gessel-Viennot引理-组合数学

    牛客网暑期ACM多校训练营(第一场) A.Monotonic Matrix 这个题就是给你一个n*m的矩阵,往里面填{0,1,2}这三种数,要求是Ai,j⩽Ai+1,j,Ai,j⩽Ai,j+1 ,问你 ...

  4. 牛客多校第六场 C Generation I 组合数学 阶乘逆元模板

    链接:https://www.nowcoder.com/acm/contest/144/C来源:牛客网 Oak is given N empty and non-repeatable sets whi ...

  5. 牛客OI测试赛 F 子序列 组合数学 欧拉降幂公式模板

    链接:https://www.nowcoder.com/acm/contest/181/F来源:牛客网 题目描述 给出一个长度为n的序列,你需要计算出所有长度为k的子序列中,除最大最小数之外所有数的乘 ...

  6. 牛牛与后缀表达式_via牛客网

    题目 链接:https://ac.nowcoder.com/acm/contest/28537/B 来源:牛客网 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 262144K,其他语 ...

  7. 欧拉函数-gcd-快速幂(牛客寒假算法基础集训营1-D-小a与黄金街道)

    题目描述: 链接:https://ac.nowcoder.com/acm/contest/317/D来源:牛客网小a和小b来到了一条布满了黄金的街道上.它们想要带几块黄金回去,然而这里的城管担心他们拿 ...

  8. 牛客练习赛38 D 出题人的手环

    链接 [https://ac.nowcoder.com/acm/contest/358/D] 题意 链接:https://ac.nowcoder.com/acm/contest/358/D 来源:牛客 ...

  9. Applese 的毒气炸弹 G 牛客寒假算法基础集训营4(图论+最小生成树)

    链接:https://ac.nowcoder.com/acm/contest/330/G来源:牛客网 Applese 的毒气炸弹 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262 ...

随机推荐

  1. MySQL| MySQL关键字和保留字

    MySQL 5.5 Keywords and Reserved Words The following list shows the keywords and reserved words in My ...

  2. Leetcode题目56.合并区间(中等)

    题目描述: 给出一个区间的集合,请合并所有重叠的区间. 示例 1: 输入: [[1,3],[2,6],[8,10],[15,18]] 输出: [[1,6],[8,10],[15,18]] 解释: 区间 ...

  3. iconfont最基础使用

    iconfont最基础使用 一.总结 一句话总结: 你加入购物车然后下载好了图标之后,里面有demo_index.html,会非常详细的教你 Unicode/Font class/Symbol三种使用 ...

  4. 记录一次webpack3升级到webpack4过程

    升级之前也参考了一些网上的教程.借鉴之,进行的自己的升级.一些版本为什么设为那个版本号也是参考别人的结果. 整体是按照先升级npm run dev:在升级npm run build的顺序. 首先升级w ...

  5. 语法错误 : 缺少“;”(在“<”的前面)

    该错误有可能是由错误所指行“<”附近的某个类型忘记#include <>所造成的

  6. Kettle源码学习(一)——把Kettle项目跑起来

    kettle(pentaho data integration),是一款开源的C/S版的ETL工具,最近打算学习一下kettle源码,并自己写一个mini kettle,并改造成基于事件触发的流处理模 ...

  7. JAVA反射机制,总结下

    1.总体概述 Java反射机制指的是在Java程序运行状态中,对于任何一个类,都可以获得这个类的所有属性和方法:对于给定的一个对象,都能够调用它的任意一个属性和方法.这种动态获取类的内容以及动态调用对 ...

  8. delphi循环校验数据集

    function XXXXXFrom.CheckData(Sender: TObject): Boolean; var tmpcds:TfwClientDataset; begin Result:=F ...

  9. 前端学习(一) body标签(下)

    今日主要内容: 列表标签 <ul>.<ol>.<dl> 表格标签 <table> 表单标签 <fom> 一.列表标签 列表标签分为三种. 1 ...

  10. spring-boot集成6:集成redis实现字典缓存功能

    Why redis? redis是基于内存的key-value系统,可以用作缓存中间件或者消息中间件,spring-boot提供了方便的方式和redis集成. 1.maven依赖 <!--red ...