Codeforces 543A Writing Code
http://codeforces.com/problemset/problem/543/A
题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b的方案数.
思路:f[i][j]代表第m行,j个bug的方案数,n^3转移
1 #include<cstdio> 2 #include<cmath> 3 #include<iostream> 4 #include<algorithm> 5 #include<cstring> 6 int n,m,b,Mod; 7 int a[200005],f[505][2005]; 8 int read(){ 9 int t=0,f=1;char ch=getchar(); 10 while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();} 11 while ('0'<=ch&&ch<='9') {t=t*10+ch-'0';ch=getchar();} 12 return t*f; 13 } 14 int main(){ 15 n=read();m=read();b=read();Mod=read(); 16 for (int i=1;i<=n;i++) a[i]=read(); 17 f[0][0]=1; 18 for (int i=1;i<=n;i++) 19 for (int j=1;j<=m;j++) 20 for (int k=b;k>=0;k--) 21 if (k>=a[i]) 22 f[j][k]=(f[j][k]+f[j-1][k-a[i]])%Mod; 23 int ans=0; 24 for (int i=0;i<=b;i++) 25 ans=(ans+f[m][i])%Mod; 26 printf("%d\n",ans); 27 }