# 洛谷P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team

 1 #include <cstdio>
2 #include <cmath>
3 #include <cstdlib>
4 #include <cstring>
5 #include <iostream>
6 #include <iomanip>
7 #include <algorithm>
8 #include <string>
9 #define LL long long
10 #define For(i,j,k) for(int i=j;i<=k;i++)
11 #define Dow(i,j,k) for(int i=j;i>=k;i--)
12 using namespace std ;
13
14 const int N = 2011,inf=1e9,Z = 1e8 ;
15 int n,mod ;
16 int f[N][1011],a[N] ;
17
18 inline LL read()
19 {
20     LL x = 0 , f = 1 ;
21     char ch = getchar() ;
22     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
23     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
24     return x * f ;
25 }
26
27 int main()
28 {
29     n = read() ; mod = read() ;
30     For(i,1,n) a[i]=read() , a[i]%=mod ;
31     For(i,0,n)
32         For(j,0,mod-1) f[i][j]=0 ;
33     f[0][0] = 1 ;
34
35     For(i,1,n) {
36         For(j,0,mod-1) {
37             f[i][j]=(f[i][j]+f[i-1][j]) % Z ;
38             f[i][j]=(f[i][j]+f[i-1][ (j-a[i]+mod) % mod ] ) % Z;
39         }
40     }
41     int ans = 0 ;
42     printf("%d\n",f[n][0]-1) ;    //  0 要减一 因为原来的f[0][0] = 1
43     return 0 ;
44 }

posted @ 2017-10-06 08:16  third2333  阅读(227)  评论(0编辑  收藏  举报