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

第二周 7.17-7.23

时间:2016-07-18 02:45:45      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:

7.17

HDU 5456 Matches Puzzle Game

没有最丑只有更丑。

技术分享
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 typedef long long LL;
 7 int num[] = { 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
 8 LL dp[555][2][2][2][2];
 9 
10 int main(void)
11 {
12     int T;
13     scanf("%d", &T);
14     for(int kase = 1; kase <= T; kase++)
15     {
16         LL n, m;
17         scanf("%I64d %I64d", &n, &m);
18         memset(dp, 0, sizeof(dp));
19         dp[n-3][0][0][0][0] = 1;
20         for(int i = n - 3; i > 0; i--)
21         {
22             for(int p1 = 0; p1 <= 1; p1++)
23             for(int p2 = 0; p2 <= 1; p2++)
24             for(int p3 = 0; p3 <= 1; p3++)
25             for(int k = 0; k <= 1; k++)
26             for(int a = 0; a <= 9; a++)
27             for(int b = 0; b <= 9; b++)
28             {
29                 if(p1 || p2 && b) continue;
30 
31                 int c = a - k - b, nk = 0;
32                 if(c < 0) c += 10, nk = 1;
33                 if(p3 && c) continue;
34 
35                 int tot = num[a];
36                 if(!p2) tot += num[b];
37                 if(!p3) tot += num[c];
38                 if(tot > i) continue;
39 
40                 for(int pp1 = 0; pp1 <= 1; pp1++)
41                 for(int pp2 = 0; pp2 <= 1; pp2++)
42                 for(int pp3 = 0; pp3 <= 1; pp3++)
43                 {
44                     if(p1 && !pp1) continue;
45                     if(p2 && !pp2) continue;
46                     if(p3 && !pp3) continue;
47                     if(pp1 && !(a && !nk)) continue;
48                     if(!p2 && pp2 && !b) continue;
49                     if(!p3 && pp3 && !c) continue;
50                     if(pp1 && !pp2) continue;
51                     if(pp1 && !pp3) continue;
52                     dp[i-tot][pp1][pp2][pp3][nk] = (dp[i-tot][pp1][pp2][pp3][nk] + dp[i][p1][p2][p3][k]) % m;
53                 }
54             }
55         }
56 
57         printf("Case #%d: %I64d\n", kase, dp[0][1][1][1][0]);
58 
59     }
60     return 0;
61 }
Aguin

 

第二周 7.17-7.23

标签:

原文地址:http://www.cnblogs.com/Aguin/p/5679678.html

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