给定一个长度为 的木板,在若干整数位置断开将它分为若干段,要求其中 个位置不能成为断点(称为标记点),定义一种划分方案的贡献为最终所有线段长度乘积的平方,求所有方案贡献之和。
组合意义天地灭,代数推导保平安。
设 为考虑前 个格子并在 和 放隔板的方案数,显然有:
考虑优化,假设 不是标记点,那么有:
设 ,有:
假设已经知道了 ,只需能求出 就能实现方程的转移,分类讨论一下:
显然可以矩阵快速幂优化,那么是不是关键点的转移矩阵分别为 和 。
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fir first
#define sec second
using namespace std;
namespace IO{
#define File(x,y) freopen(#x,"r",stdin),freopen(#y,"w",stdout)
#define fill(a,b,c,d) memset(a,b,sizeof(c)*(d+1))
#define fillall(x,y) memset(x,y,sizeof(x))
inline int read(){
int w=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){w=(w<<1)+(w<<3)+(ch^48); ch=getchar();}
return w*f;
}
}
using namespace IO;
namespace CL{
const int mod=1e9+7;
int n,m;
namespace Matrix{
struct matrix{
ll p[4][4];
matrix(){fillall(p,0);}
inline void build(){for(int i=1;i<=3;i++) p[i][i]=1;}
inline matrix operator *(const matrix &x)const{
matrix res;
for(int i=1;i<=3;i++)
for(int k=1;k<=3;k++) if(p[i][k])
for(int j=1;j<=3;j++)
res.p[i][j]=(res.p[i][j]+p[i][k]*x.p[k][j])%mod;
return res;
}
}t1,t2,f,tmp;
inline matrix qpow(matrix x,int y){
matrix res; res.build();
for(;y;y>>=1,x=x*x) if(y&1) res=res*x;
return res;
}
}using namespace Matrix;
inline int main(){
n=read(),m=read();
t1.p[1][1]=t1.p[1][3]=t1.p[2][1]=t1.p[2][2]=t1.p[2][3]=t1.p[3][1]=1,t1.p[3][2]=t1.p[3][3]=2;
t2.p[1][1]=t2.p[2][1]=t2.p[2][2]=t2.p[3][1]=t2.p[3][3]=1,t2.p[3][2]=2;
f.p[1][1]=f.p[2][1]=f.p[3][1]=1;
int lst=1;
for(int i=1;i<=m;i++){
int x=read();
tmp=qpow(t1,x-lst),f=tmp*f,f=t2*f;
lst=x+1;
}
tmp=qpow(t1,n-lst),f=tmp*f;
printf("%lld\n",f.p[3][1]);
return 0;
}
}
signed main(){return CL::main();}