Matches Puzzle Game

Matches Puzzle Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5456

数位DP

首先我把C-A=B改为A+B=C(我觉得会简单一点<( ̄3 ̄)>)

注意到前面填的数字不影响后面的数字,所以可以定义状态:

dp[i][j][a][b]表示已经用了i根火柴,进位为j,A前面能否再加数字(a),B前面能否再加数字(b)

然后根据a和b的值进行分类讨论即可。

(最近期中考好烦啊好多事都没弄)

代码如下:

 1 /*苟利国家生死已,岂因祸福避趋之*/
 2 #include<cstdio>
 3 #include<iostream>
 4 #include<cstring>
 5 #define MATCH 505
 6 #define TOWARDS 2
 7 #define FA 2//前止
 8 #define FB 2
 9 using namespace std;
10 typedef long long LL;
11 LL p[]={6,2,5,5,4,5,6,3,7,6};
12 LL T,n,m,dp[MATCH][TOWARDS][FA][FB];
13 void init(){
14     memset(dp,0,sizeof(dp));
15     dp[0][0][0][0]=1;
16     scanf("%I64d%I64d",&n,&m);
17     n-=3;
18 }
19 int main(void){
20     scanf("%I64d",&T);
21     for(LL times=1;times<=T;++times){
22         init();
23         for(LL i=0;i<n;++i)
24         for(LL j=0;j<2;++j)
25         for(LL a=0;a<2;++a)
26         for(LL b=0;b<2;++b)
27         if(dp[i][j][a][b]){
28             if(a==1&&b==1&&j==1&&i+p[1]<=n){
29                 dp[i+p[1]][0][1][1]=(dp[i+p[1]][0][1][1]+dp[i][j][a][b])%m;
30             }else if(a==1&&b==0){
31                 for(LL x=0;x<=9;++x){
32                     LL r=x+j;
33                     LL rr=i+p[x]+p[r%10];
34                     if(rr<=n){
35                         dp[rr][r/10][a][0]=(dp[rr][r/10][a][0]+dp[i][j][a][b])%m;
36                         if(x!=0)dp[rr][r/10][a][1]=(dp[rr][r/10][a][1]+dp[i][j][a][b])%m;
37                     }
38                 }
39             }else if(a==0&&b==1){
40                 for(LL x=0;x<=9;++x){
41                     LL r=x+j;
42                     LL rr=i+p[x]+p[r%10];
43                     if(rr<=n){
44                         dp[rr][r/10][0][b]=(dp[rr][r/10][0][b]+dp[i][j][a][b])%m;
45                         if(x!=0)dp[rr][r/10][1][b]=(dp[rr][r/10][1][b]+dp[i][j][a][b])%m;
46                     }
47                 }
48             }else if(a==0&&b==0){
49                 for(LL x=0;x<=9;++x)
50                 for(LL y=0;y<=9;++y){
51                     LL r=x+y+j;
52                     LL rr=i+p[x]+p[y]+p[r%10];
53                     if(rr<=n){
54                         dp[rr][r/10][a][b]=(dp[rr][r/10][a][b]+dp[i][j][a][b])%m;
55                         if(x!=0)dp[rr][r/10][1][b]=(dp[rr][r/10][1][b]+dp[i][j][a][b])%m;
56                         if(y!=0)dp[rr][r/10][a][1]=(dp[rr][r/10][a][1]+dp[i][j][a][b])%m;
57                         if(x!=0&&y!=0)dp[rr][r/10][1][1]=(dp[rr][r/10][1][1]+dp[i][j][a][b])%m;
58                     }
59                 }
60             }
61         }
62         printf("Case #%I64d: %I64d\n",times,dp[n][0][1][1]);
63     }
64 }
时间: 2024-08-27 14:00:06

Matches Puzzle Game的相关文章

2015 ACM/ICPC Asia Regional Shenyang Online

1001 Traversal 1002 Best Solver 1003 Minimum Cut 1004 Dividing This Product 1005 Excited Database 1006 Fang Fang 1007 Matches Puzzle Game 1008 Hold Your Hand 1009 Stability 1010 Jesus Is Here 1011 Poker 1012 Largest Point 1013 Manors

第二周 7.17-7.23

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 d

2015年ACM沈阳网络赛(准备做掉4道:)

Traversal Best Solver Minimum Cut Dividing This Product Excited Database Fang Fang Matches Puzzle Game Hold Your Hand Stability Jesus Is Here Poker Largest Point Manors

解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题

解决Android中No resource found that matches android:TextAppearance.Material.Widget.Button.Inverse问题http://blog.csdn.net/u012336923/article/details/48289485 /路径/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/res/values-v23/v

编译或运行时可能会出现错误: Error:Error retrieving parent for item: No resource found that matches the given name “Theme.AppCompat.Light”

这个问题我在刚开始写"HelloWorld"时就遇到,以为是API版本太高,下载了常用的API 19.17--一系列的,后来还是有问题.就上网查了很多,遇到几篇不错的文章,记录下来,方便以后查看. No resource found that matches the given name 'Theme.AppCompat.Light 的完美解决方案  http://www.360doc.com/content/15/0316/15/9200790_455576135.shtml And

【转】eclipse新建项目,报错“Error: workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matches the given name”

原文网址:http://www.cnblogs.com/mbp-study/p/5268478.html 新建项目报错,不知道为什么,以前从未出现过的错误,把sdk更新之后,出现莫名错误,自己也是一知半解,在网上找了好久的错误,终于在一个english网站找到了解决方法,soga,从未觉得english如此美好 错误信息如下 ....\appcompat_v7\res\values-v21\styles_base.xml:75: error: Error retrieving parent fo

UVa - 227 - Puzzle

给空格子上下左右的互换操作,问最后是怎样的 注意一行的最后一个若是空格,需要自己加注意读取时 操作可能分好多行,一定要读取到 0 为止 1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 char map[50][50],op[1000],c,tmp; 5 int k,t,x,y,cnt; 6 bool flag; 7 void fuc() 8 { 9 flag=1; 10 for(int i=0;

HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 269 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) 问题描述 克拉克是一名人格分裂患者.某一天,有两个克拉克(aa和bb)在玩一个方格游戏. 这个方格是一个n*mn∗m的矩阵,每个格子里有一

HDU 1098 Ignatius&#39;s puzzle 费马小定理+扩展欧几里德算法

题目大意: 给定k,找到一个满足的a使任意的x都满足 f(x)=5*x^13+13*x^5+k*a*x 被65整除 推证: f(x) = (5*x^12 + 13 * x^4 + ak) * x 因为x可以任意取 那么不能总是满足 65|x 那么必须是 65 | (5*x^12 + 13 * x^4 + ak) 那么就是说 x^12 / 13 + x^4 / 5 + ak / 65 正好是一个整数 假设能找到满足的a , 那么将 ak / 65 分进x^12 / 13 + x^4 / 5中得到