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
时间: 2024-10-20 05:00:02