| 比赛 |
寒假集训2 |
评测结果 |
AAAMMMMMMMMMMMMMMMMM |
| 题目名称 |
组合数问题 |
最终得分 |
15 |
| 用户昵称 |
rzzakioi |
运行时间 |
5.060 s |
| 代码语言 |
C++ |
内存使用 |
2.64 MiB |
| 提交时间 |
2026-02-25 12:16:35 |
显示代码纯文本
#include<cstdio>
#define int long long
using namespace std;
int n,x,p,m,f[1005],a[1005],c[1005][1005];
int fpow(int a,int b){
int ans=1;
while(b){
if(b&1){
ans*=a;
ans%=p;
}
a*=a;
a%=p;
b>>=1;
}
return ans;
}
signed main(){
freopen("problem.in","r",stdin);
freopen("problem.out","w",stdout);
scanf("%lld%lld%lld%lld",&n,&x,&p,&m);
for(int i=0;i<=m;i++)scanf("%lld",&a[i]);
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
f[i]+=a[j]*fpow(i,j);
f[i]%=p;
}
}
c[0][0]=1;
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
if(i>0){
c[i][j]+=c[i-1][j];
c[i][j]%=p;
if(j>0){
c[i][j]+=c[i-1][j-1];
c[i][j]%=p;
}
}
c[i][j]%=p;
}
}
int ans=0;
for(int k=0;k<=n;k++){
ans+=(((f[k]*fpow(x,k))%p)*c[n][k])%p;
ans%=p;
}
printf("%lld",ans);
return 0;
}