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 ...
随机推荐
- ng-if 和 ng-show/ng-hide 之间的区别
ng-if会移除dom,生成dom,而ng-show只是改变其display属性.所以你自己看着用吧.
- lepus bug
------------------------------------------------BUG fix-------------------------------------------- ...
- 实战WEB 服务器(JAVA编写WEB服务器)
实战WEB 服务器(JAVA编写WEB服务器) 标签: web服务服务器javawebsockethttp服务器 2010-04-21 17:09 11631人阅读 评论(24) 收藏 举报 分类: ...
- json-c代码示例
#include <stdio.h> #include <string.h> #include <json.h> int main(int argc,char ** ...
- sql 日结
--生成日结数据 ==================================== -- Author: <Author,,Name> -- Create date: <Cr ...
- java 子类与父类继承关系
People.java public class People { int age,leg = 2,hand = 2; protected void showPeopleMess() { System ...
- Override/implements methods 如何添加
用过Eclipse 的ADT的都知道,要快速添加override或者implements方法,右键---Source---Override/Implements Method... 中文:右键---& ...
- JDBC的超时原理
1.什么是JDBC jdbc是业务系统连接数据的标准API.SUN公司一共定义了4中类型的JDBC:JDBC-ODBC桥:Native-API 驱动:Network-Protocol 驱动:Datab ...
- Java Web 错误排查
排查404 1. 检查web.xml,有没有放在web-inf下面,再检查过滤器有没有配置 <filter> <filter-name>struts</filter-na ...
- php五大运行模式CGI,FAST-CGI,CLI,ISAPI,APACHE模式浅谈
做 php 开发的应该都知道 php 运行模式概念吧,本文将要和大家分享的是关于php目前比较常见的五大运行模式:包括cgi .fast-cgi.cli.isapi.apache模块的DLL ,下面作 ...