比赛 寒假集训2 评测结果 WWWEEEEEEEEEEEEEEEEE
题目名称 组合数问题 最终得分 0
用户昵称 PXCZM 运行时间 2.772 s
代码语言 C++ 内存使用 7.93 MiB
提交时间 2026-02-25 11:20:18
显示代码纯文本
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,x,p,m;
ll a[1010],b[1010][1010];
ll ans;
int main()
{
    freopen("problem.in","r",stdin);
    freopen("problem.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    cin>>n>>x>>p>>m;
    for(int i=0;i<=n;i++) b[i][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            b[i][j]=(b[i-1][j]+b[i-1][j-1])%p;
    for(int i=0;i<=m;i++) cin>>a[i];
    for(ll i=0,tp2=1;i<=n;i++,tp2=tp2*x%p)
    {
        ll tp1=0,tp3=b[n][i];
        for(ll j=0,k=1;j<=m;j++,k=k*i%p) tp1=(tp1+a[j]*k)%p;
        ans=(ans+tp1*tp2*tp3%p)%p;
    }
    cout<<ans;
    return 0;
}