博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
牛客 109 C 操作数 (组合数学)
阅读量:4628 次
发布时间:2019-06-09

本文共 2075 字,大约阅读时间需要 6 分钟。

给定长度为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 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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<
<<' ';hr;})using namespace std;typedef long long ll;typedef pair
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;}//headconst 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;}

 

转载于:https://www.cnblogs.com/uid001/p/10944305.html

你可能感兴趣的文章
POJ 2234 Matches Game 博弈论水题 Nim模型
查看>>
BBC-unit6 session4
查看>>
JS获取节点的兄弟,父级,子级元素的方法(js获取子级获取到换行与空格元素-FF)...
查看>>
ini文件操作
查看>>
Win7 本地打印后台处理程序服务没有运 怎么办
查看>>
php 中array_multisort排序,类似于对数据库中的记录依次按多列进行排序
查看>>
加密算法和MD5等散列算法的区别
查看>>
【python】函数返回值
查看>>
Java基础50题test9—求完数
查看>>
【记忆法】心智绘图
查看>>
Unable to create request (bad url?) 解决方案
查看>>
网络对抗技术_实验三_密码破解技术
查看>>
spoj104 highways 生成树计数(矩阵树定理)
查看>>
nginx配置多个域名
查看>>
ARM寻址方式
查看>>
pandas之时间序列
查看>>
补肾的十大食物是什么?
查看>>
iPhone开发之 - 苹果推送通知服务(APNs)编程
查看>>
ASP常用读取数据2个调用方式
查看>>
【大话UWB定位】之蓝牙定位的烦恼
查看>>