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

Posted third2333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了洛谷P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team相关的知识,希望对你有一定的参考价值。

洛谷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 }

 

以上是关于洛谷P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team的主要内容,如果未能解决你的问题,请参考以下文章

P2946 [USACO09MAR]牛飞盘队Cow Frisbee Team

洛谷P2947 [USACO09MAR]仰望Look Up

牛飞盘队Cow Frisbee Team

洛谷 P2945 [USACO09MAR]沙堡Sand Castle

洛谷2944 [USACO09MAR]地震损失2Earthquake Damage 2

洛谷P2880 [USACO07JAN]平衡的阵容Balanced Lineup(st表)