因为第一行和最后一行都是0,我们只需枚举最左边或最右边一列的01情况,即可得到整张表

然后再检验表是否符合要求

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<vector>
  4. #include<cmath>
  5. #include<queue>
  6. #include<list>
  7. #include<algorithm>
  8. using namespace std;
  9.  
  10. int T;
  11. int n,m;
  12. int a[][],ans[][],pri[][];
  13. int b[];
  14. int num;
  15. int Y;
  16.  
  17. bool f(int x,int y)
  18. {
  19. if(x>=&&x<n&&y>=&&y<m) return ;
  20. return ;
  21. }
  22.  
  23. int getSum(int i,int j)
  24. {
  25. int res=;
  26. if(f(i-,j-)) res=res+ans[i-][j-];
  27. if(f(i-,j)) res=res+ans[i-][j];
  28. if(f(i-,j+)) res=res+ans[i-][j+];
  29. if(f(i,j-)) res=res+ans[i][j-];
  30. if(f(i,j)) res=res+ans[i][j];
  31. if(f(i,j+)) res=res+ans[i][j+];
  32. if(f(i+,j-)) res=res+ans[i+][j-];
  33. if(f(i+,j)) res=res+ans[i+][j];
  34. if(f(i+,j+)) res=res+ans[i+][j+];
  35. return res;
  36. }
  37.  
  38. void dfs(int tot)
  39. {
  40. if(tot==n-)
  41. {
  42. bool fail=;
  43.  
  44. //填表
  45. memset(ans,,sizeof ans);
  46. for(int i=;i<m;i++) ans[][i]=,ans[n-][i]=;
  47. for(int i=;i<=n-;i++) ans[i][]=b[i-];
  48. for(int j=;j<=m-;j++)
  49. for(int i=;i<=n-;i++)
  50. ans[i][j]=a[i-][j-]-getSum(i-,j-);
  51.  
  52. //填完检查
  53. for(int i=;i<n;i++)
  54. {
  55. for(int j=;j<m;j++)
  56. {
  57. if(a[i][j]!=getSum(i,j)) fail=;
  58. if(ans[i][j]!=&&ans[i][j]!=) fail=;
  59. }
  60. }
  61.  
  62. if(fail==)
  63. {
  64. num++;
  65. if(num==) Y=;
  66. else if(num==)
  67. {
  68. for(int i=;i<n;i++)
  69. for(int j=;j<m;j++)
  70. pri[i][j]=ans[i][j];
  71. }
  72. }
  73. return;
  74. }
  75.  
  76. b[tot]=;
  77. dfs(tot+); if(Y) return;
  78. b[tot]=;
  79. dfs(tot+); if(Y) return;
  80. }
  81.  
  82. int main()
  83. {
  84. scanf("%d",&T);
  85. while(T--)
  86. {
  87. scanf("%d%d",&n,&m);
  88. for(int i=;i<n;i++)
  89. for(int j=;j<m;j++)
  90. scanf("%d",&a[i][j]);
  91. if(m==)
  92. {
  93. printf("Impossible\n");
  94. continue;
  95. }
  96. num=;Y=;
  97. dfs();
  98. if(Y==) printf("Multiple\n");
  99. else if(num==)
  100. {
  101. for(int i=;i<n;i++)
  102. {
  103. for(int j=;j<m;j++)
  104. {
  105. printf("%d",pri[i][j]);
  106. if(j<m-) printf(" ");
  107. else printf("\n");
  108. }
  109. }
  110. }
  111. else printf("Impossible\n");
  112. }
  113. return ;
  114. }

HDU 5613 Baby Ming and Binary image的更多相关文章

  1. hdu 5612 Baby Ming and Matrix games

    Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...

  2. hdu 5612 Baby Ming and Matrix games(dfs暴力)

    Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...

  3. hdu 5611 Baby Ming and phone number(模拟)

    Problem Description Baby Ming collected lots of cell phone numbers, and he wants to sell them for mo ...

  4. hdu 5610 Baby Ming and Weight lifting

    Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which c ...

  5. HDU 5612 Baby Ming and Matrix games(DFS)

    题目链接 题解:题意为给出一个N*M的矩阵,然后(i∗2,j∗2) (i,j=0,1,2...)的点处是数字,两个数字之间是符号,其他位置是‘#’号. 但不知道是理解的问题还是题目描述的问题,数据中还 ...

  6. HDU 5611 Baby Ming and phone number

    #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include ...

  7. HDU 5614 Baby Ming and Matrix tree 树链剖分

    题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...

  8. BestCoder Round #69 (div.2) Baby Ming and Weight lifting(hdu 5610)

    Baby Ming and Weight lifting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  9. Baby Ming and Matrix games(dfs计算表达式)

    Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

随机推荐

  1. 巧妙使用Contains()方法查找一个数是否在某堆数中

    问题:要判断用户输入的一个数,或者是程序里方法的一个参数的值,或者是一个变量的值是否在某堆数中. 简洁写法:把这堆数放在list中,使用list的Contains()方法检查list是否包含这个数,取 ...

  2. EL(表达式语言)

    EL(Expression Language):目的是为了简化Jsp页面的语言,使页面看起来更加简洁 基本的语法特点 以“${"开头,以”}“结束 一 与低版本的环境兼容----禁用EL ( ...

  3. css 重新学习系列(2)

    摘自: http://www.cnblogs.com/liuzhaoyang/articles/3289456.html Position定位:relative | absolute 定位一直是WEB ...

  4. encodeURIComponent与URLDecoder.decode用法

    在输入地址栏时有时一些信息需要在地址栏看不见,我们就需要对其信息在前台转码后台解码 js:encodeURIComponent编码与解码 今天在js往jsp和servlet传参的时候出现:JavaSc ...

  5. ajax2016/4/15 post与get

    post方式,数据放在send()里面作为参数传递 xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); ...

  6. C语言开发工具

    1.编写程序的工具: indent命令将自动调整C代码的缩进风格,个人比较喜欢indent -kr 2.编译C语言程序: 1.gcc编译器: gcc是一个ANSI C兼容编译器,C++编译器也可以编译 ...

  7. lucene特殊字符处理

    这是个郁闷的问题,今天遇到了,但在lucene中查询的关键字保护有特殊字符,譬如--,会出现如下异常: org.apache.lucene.queryParser.ParseException: Ca ...

  8. Code Blocks 使用 VC2013编译HelloWord

    首先在 Settings-Complier中把 Microsoft Visual c++ 2010 设置成默认(莫不默认也无所谓,就是改着方便而已) 然后在ToolChain excutable 中, ...

  9. jquery指定div右键事件

    <div class="nav_list_item">需要淡季右键的div</div> 我们要 给这个div注册鼠标右键的时候需要先禁用该div的网页右键菜 ...

  10. JSP标准标签库(JSTL)--JSTL简介与安装

    对于MVC设计模式来讲,我们一直强调,在一个JSP钟scriptlet代码越少越好,但是只靠以前的概念很难实现,因为标签的开发特别麻烦,所以为了简化标签,也为了让标签更具备一些通用性,所以一般在开发中 ...