HDU 5613 Baby Ming and Binary image
因为第一行和最后一行都是0,我们只需枚举最左边或最右边一列的01情况,即可得到整张表
然后再检验表是否符合要求
- #include<cstdio>
- #include<cstring>
- #include<vector>
- #include<cmath>
- #include<queue>
- #include<list>
- #include<algorithm>
- using namespace std;
- int T;
- int n,m;
- int a[][],ans[][],pri[][];
- int b[];
- int num;
- int Y;
- bool f(int x,int y)
- {
- if(x>=&&x<n&&y>=&&y<m) return ;
- return ;
- }
- int getSum(int i,int j)
- {
- int res=;
- if(f(i-,j-)) res=res+ans[i-][j-];
- if(f(i-,j)) res=res+ans[i-][j];
- if(f(i-,j+)) res=res+ans[i-][j+];
- if(f(i,j-)) res=res+ans[i][j-];
- if(f(i,j)) res=res+ans[i][j];
- if(f(i,j+)) res=res+ans[i][j+];
- if(f(i+,j-)) res=res+ans[i+][j-];
- if(f(i+,j)) res=res+ans[i+][j];
- if(f(i+,j+)) res=res+ans[i+][j+];
- return res;
- }
- void dfs(int tot)
- {
- if(tot==n-)
- {
- bool fail=;
- //填表
- memset(ans,,sizeof ans);
- for(int i=;i<m;i++) ans[][i]=,ans[n-][i]=;
- for(int i=;i<=n-;i++) ans[i][]=b[i-];
- for(int j=;j<=m-;j++)
- for(int i=;i<=n-;i++)
- ans[i][j]=a[i-][j-]-getSum(i-,j-);
- //填完检查
- for(int i=;i<n;i++)
- {
- for(int j=;j<m;j++)
- {
- if(a[i][j]!=getSum(i,j)) fail=;
- if(ans[i][j]!=&&ans[i][j]!=) fail=;
- }
- }
- if(fail==)
- {
- num++;
- if(num==) Y=;
- else if(num==)
- {
- for(int i=;i<n;i++)
- for(int j=;j<m;j++)
- pri[i][j]=ans[i][j];
- }
- }
- return;
- }
- b[tot]=;
- dfs(tot+); if(Y) return;
- b[tot]=;
- dfs(tot+); if(Y) return;
- }
- int main()
- {
- scanf("%d",&T);
- while(T--)
- {
- scanf("%d%d",&n,&m);
- for(int i=;i<n;i++)
- for(int j=;j<m;j++)
- scanf("%d",&a[i][j]);
- if(m==)
- {
- printf("Impossible\n");
- continue;
- }
- num=;Y=;
- dfs();
- if(Y==) printf("Multiple\n");
- else if(num==)
- {
- for(int i=;i<n;i++)
- {
- for(int j=;j<m;j++)
- {
- printf("%d",pri[i][j]);
- if(j<m-) printf(" ");
- else printf("\n");
- }
- }
- }
- else printf("Impossible\n");
- }
- return ;
- }
HDU 5613 Baby Ming and Binary image的更多相关文章
- hdu 5612 Baby Ming and Matrix games
Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 5612 Baby Ming and Matrix games(DFS)
题目链接 题解:题意为给出一个N*M的矩阵,然后(i∗2,j∗2) (i,j=0,1,2...)的点处是数字,两个数字之间是符号,其他位置是‘#’号. 但不知道是理解的问题还是题目描述的问题,数据中还 ...
- HDU 5611 Baby Ming and phone number
#include<cstdio> #include<cstring> #include<vector> #include<cmath> #include ...
- HDU 5614 Baby Ming and Matrix tree 树链剖分
题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...
- 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 ( ...
- Baby Ming and Matrix games(dfs计算表达式)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
随机推荐
- 巧妙使用Contains()方法查找一个数是否在某堆数中
问题:要判断用户输入的一个数,或者是程序里方法的一个参数的值,或者是一个变量的值是否在某堆数中. 简洁写法:把这堆数放在list中,使用list的Contains()方法检查list是否包含这个数,取 ...
- EL(表达式语言)
EL(Expression Language):目的是为了简化Jsp页面的语言,使页面看起来更加简洁 基本的语法特点 以“${"开头,以”}“结束 一 与低版本的环境兼容----禁用EL ( ...
- css 重新学习系列(2)
摘自: http://www.cnblogs.com/liuzhaoyang/articles/3289456.html Position定位:relative | absolute 定位一直是WEB ...
- encodeURIComponent与URLDecoder.decode用法
在输入地址栏时有时一些信息需要在地址栏看不见,我们就需要对其信息在前台转码后台解码 js:encodeURIComponent编码与解码 今天在js往jsp和servlet传参的时候出现:JavaSc ...
- ajax2016/4/15 post与get
post方式,数据放在send()里面作为参数传递 xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); ...
- C语言开发工具
1.编写程序的工具: indent命令将自动调整C代码的缩进风格,个人比较喜欢indent -kr 2.编译C语言程序: 1.gcc编译器: gcc是一个ANSI C兼容编译器,C++编译器也可以编译 ...
- lucene特殊字符处理
这是个郁闷的问题,今天遇到了,但在lucene中查询的关键字保护有特殊字符,譬如--,会出现如下异常: org.apache.lucene.queryParser.ParseException: Ca ...
- Code Blocks 使用 VC2013编译HelloWord
首先在 Settings-Complier中把 Microsoft Visual c++ 2010 设置成默认(莫不默认也无所谓,就是改着方便而已) 然后在ToolChain excutable 中, ...
- jquery指定div右键事件
<div class="nav_list_item">需要淡季右键的div</div> 我们要 给这个div注册鼠标右键的时候需要先禁用该div的网页右键菜 ...
- JSP标准标签库(JSTL)--JSTL简介与安装
对于MVC设计模式来讲,我们一直强调,在一个JSP钟scriptlet代码越少越好,但是只靠以前的概念很难实现,因为标签的开发特别麻烦,所以为了简化标签,也为了让标签更具备一些通用性,所以一般在开发中 ...