一开始,没敢写,感觉会超时。。。其实就是暴力搜索。DFS

 #include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<queue>
#define clc(a,b) memset(a,b,sizeof(a))
#define N 100
#define eps 1e-6
#include<stack>
#include<deque>
#include<vector>
using namespace std;
const int MAXD = 1e5+;
const int MAXM = ;
const int INF = 0x3f3f3f3f;
typedef long long ll; char G[][];
int row[][],coloum[][],cr[][],row1[];
int t;
int sum;
void dfs(int x,int y)
{
if(x==)
{
sum++;
return;
}
if(G[x][y]>=''&&G[x][y]<='')
{
if(y==)
dfs(x+,);
else
dfs(x,y+);
return ;
}
else if(G[x][y]=='e')
{
int flag=;
for(int i=; i<; i=i+)
{
if(!row[x][i]&&!coloum[y][i]&&!cr[(x/)*+y/+][i])
{
flag=;
G[x][y]=i+'';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
if(y==)
dfs(x+,);
else
dfs(x,y+);
G[x][y]='e';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
}
}
if(!flag)
return;
}
else if(G[x][y]=='o')
{
int flag=;
for(int i=; i<=; i=i+)
{
if(!row[x][i]&&!coloum[y][i]&&!cr[(x/)*+y/+][i])
{
flag=;
G[x][y]=i+'';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
if(y==)
dfs(x+,);
else
dfs(x,y+);
G[x][y]='o';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
}
}
if(!flag)
return ;
}
else if(G[x][y]>='a'&&G[x][y]<='z'&&G[x][y]!='e'&&G[x][y]!='o')
{
int num=G[x][y]-'a';
if(row1[num])
{
if(!row[x][row1[num]]&&!coloum[y][row1[num]]&&!cr[(x/)*+y/+][row1[num]])
{
G[x][y]=row1[num]+'';
row[x][row1[num]]=;
coloum[y][row1[num]]=;
cr[(x/)*+y/+][row1[num]]=;
if(y==)
dfs(x+,);
else
dfs(x,y+);
G[x][y]=num+'a';
row[x][row1[num]]=;
coloum[y][row1[num]]=;
cr[(x/)*+y/+][row1[num]]=;
}
else
return ;
}
else
{
int flag=;
for(int i=; i<=; i++)
{
if(row[x][i]==&&coloum[y][i]==&&cr[(x/)*+y/+][i]==)
{
flag=;
row1[num]=i;
G[x][y]=i+'';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
if(y==)
dfs(x+,);
else
dfs(x,y+);
G[x][y]=num+'a';
row1[num]=;
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
}
}
if(flag==)
return ;
}
}
else if(G[x][y]=='')
{
int flag=;
for(int i=; i<=; i++)
{
if(!row[x][i]&&!coloum[y][i]&&cr[(x/)*+y/+][i]==)
{
flag=;
G[x][y]=i+'';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
if(y==)
dfs(x+,);
else
dfs(x,y+);
G[x][y]='';
row[x][i]=;
coloum[y][i]=;
cr[(x/)*+y/+][i]=;
}
}
if(flag==)
return;
}
} int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&t);
while(t--)
{
sum=;
clc(row,);
clc(coloum,);
clc(cr,);
clc(row1,);
for(int i=;i<;i++)
{
scanf("%s",G[i]);
}
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{ if(G[i][j]>=''&&G[i][j]<='')
{
row[i][G[i][j]-'']=;
coloum[j][G[i][j]-'']=;
cr[(i/)*+j/+][G[i][j]-'']=;
}
}
}
dfs(,);
printf("%d\n",sum);
}
return ;
}

UVALive 4763的更多相关文章

  1. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  2. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  3. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  4. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  5. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  6. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  7. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  8. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

  9. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

随机推荐

  1. REACTOS(193)与汇编编译器(69)的高人

    REACTOS(193)与汇编编译器(69)的高人http://blog.csdn.net/caimouse ReactOS编译成VS工程1: 首先从https://www.reactos.org/w ...

  2. jQuery好用插件

    jQuery图片轮播插件(smallslider):http://fz.sjtu.edu.cn/zsw/js/smallslider/ jQuery消息通知(noty):http://www.360d ...

  3. JBoss - 调整JVM内存 -Xms512m -Xmx1024m

    $JBOSS-HOME/server/下有3个目录,all/default/minimal,它们是表示3种配置,全部的配置.默认配置.最小配置,我们在启动JBOSS服务时,可以指定 run –c al ...

  4. 机器学习 —— 概率图模型(Homework: Exact Inference)

    在前三周的作业中,我构造了概率图模型并调用第三方的求解器对器进行了求解,最终获得了每个随机变量的分布(有向图),最大后验分布(双向图).本周作业的主要内容就是自行编写概率图模型的求解器.实际上,从根本 ...

  5. hadoop拾遗(二)---- 文件模式

    在单个操作中处理一批文件,这是一个常见的要求.举例来说,处理日志的MapReduce作业可能需要分析一个月内包含在大量目录中的日志文件.在一个表达式中使用通配符来匹配多个文件是比较方便的,无需列举第个 ...

  6. 深度神经网络如何看待你,论自拍What a Deep Neural Network thinks about your #selfie

    Convolutional Neural Networks are great: they recognize things, places and people in your personal p ...

  7. opencv绘制灰度直方图

    代码之一: #include <cv.h> #include <highgui.h> #pragma comment( lib, "cv.lib" ) #p ...

  8. android logcat里面AndroidRuntime FATAL EXCEPTION: main这个是什么问题啊。

    android logcat里面AndroidRuntime FATAL EXCEPTION: main这个是什么问题啊. http://zhidao.baidu.com/link?url=mUI11 ...

  9. Android开发之定义接口暴露数据

    写了一个网络请求的工具类,然后想要获取到网络请求的结果,在网络工具类中写了一个接口,暴露除了请求到的数据 代码: package com.lijingbo.knowweather.utils; imp ...

  10. Awesome Javascript(中文翻译版)

    [导读]:GitHub 上有一个 Awesome – XXX 系列的资源整理.awesome-javascript 是 sorrycc 发起维护的 JS 资源列表,内容包括:包管理器.加载器.测试框架 ...