分析:
CF官方题解:http://codeforces.com/blog/entry/62411
不错的,很锻炼思维的一道组合数学题。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
typedef long long LL;
inline int read(){
int x=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x;
}
const int MAXM=200005;
const LL MOD=998244353;
const LL INV2=499122177;
int n,m,siz,b[MAXM];
inline LL qpow(LL x,LL y){
LL ret=1,tt=x%MOD;
while(y){
if(y&1) ret=ret*tt%MOD;
tt=tt*tt%MOD;
y>>=1;
}
return ret;
}
inline LL cnt(int x){
LL temp=qpow(siz,x);
return (temp+1)*temp%MOD*INV2%MOD;
}
int main(){
n=read(),m=read(),siz=read();
for(int i=1;i<=m;i++) b[i]=read();
LL ans=qpow(siz,n-b[m]*2);
for(int i=1;i<=m;i++)
ans=ans*cnt(b[i]-b[i-1])%MOD;
printf("%I64d\n",ans);
return 0;
}