zoukankan      html  css  js  c++  java
  • 洛谷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
    ",f[n][0]-1) ;    //  0 要减一 因为原来的f[0][0] = 1  
    43     return 0 ; 
    44 }
  • 相关阅读:
    常见问题
    查询
    多对多关系
    prototype & __proto__
    new operator
    用户
    express.Router
    Express 应用生成器
    LeanCloud
    npm常用命令
  • 原文地址:https://www.cnblogs.com/third2333/p/7630572.html
Copyright © 2011-2022 走看看