http://codeforces.com/problemset/problem/543/A
题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b的方案数.
思路:f[i][j]代表第m行,j个bug的方案数,n^3转移
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
int n,m,b,Mod;
int a[],f[][];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<='') {t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
n=read();m=read();b=read();Mod=read();
for (int i=;i<=n;i++) a[i]=read();
f[][]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
for (int k=b;k>=;k--)
if (k>=a[i])
f[j][k]=(f[j][k]+f[j-][k-a[i]])%Mod;
int ans=;
for (int i=;i<=b;i++)
ans=(ans+f[m][i])%Mod;
printf("%d\n",ans);
}