码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5389 dp

时间:2015-08-13 19:48:24      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

写错一个地方WA了一下午...

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 
 6 const int MOD = 258280327;
 7 const int N = 100001;
 8 const int M = 10;
 9 int id[N];
10 int dp[M];
11 int help[M];
12 
13 int main ()
14 {
15     int t;
16     scanf("%d", &t);
17     while ( t-- )
18     {
19         int n, a, b, sum = 0;
20         scanf("%d%d%d", &n, &a, &b);
21         for ( int i = 1; i <= n; i++ )
22         {
23             scanf("%d", id + i);
24             sum += id[i];
25             if ( sum > 9 ) sum -= 9;
26         }
27         int ab = a + b;
28         if ( ab > 9 ) ab -= 9;
29         if ( ab == sum )
30         {
31             memset( dp, 0, sizeof(dp) );
32             for ( int i = 1; i <= n; i++ )
33             {
34                 for ( int j = 1; j < M; j++ )
35                 {
36                     int tmp = j + id[i];
37                     if ( tmp > 9 ) tmp -= 9;
38                     help[tmp] = dp[j];
39                 }
40                 for ( int j = 1; j < M; j++ )
41                 {
42                     int tmp = j + id[i];
43                     if ( tmp > 9 ) tmp -= 9;
44                     dp[tmp] += help[tmp];
45                     if ( dp[tmp] >= MOD ) dp[tmp] -= MOD;
46                 }
47                 dp[id[i]]++;
48                 if ( dp[id[i]] >= MOD ) dp[id[i]] -= MOD;
49             }
50             if ( b == sum )
51             {
52                 printf("%d\n", ( dp[a] + 1 ) % MOD);
53             }
54             else
55             {
56                 printf("%d\n", dp[a]);
57             }
58         }
59         else
60         {
61             if ( sum == a || sum == b )
62             {
63                 if ( a == b ) printf("2\n");
64                 else printf("1\n");
65             }
66             else
67             {
68                 printf("0\n");
69             }
70         }
71     }
72     return 0;
73 }

 

hdu 5389 dp

标签:

原文地址:http://www.cnblogs.com/huoxiayu/p/4728233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!