一开始,没敢写,感觉会超时。。。其实就是暴力搜索。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. SQLite数据库的体系结构(翻译自sqlite.org)

    $1 简介    本文档描述了SQLite库的体系结构,这些信息对那些想理解和修改SQLite的内部工作机制的人是有用的.    下图显示了SQLite的主要组成部件及其相互关系,下面的内容将描述每一 ...

  2. 解决Nginx下WordPress后台404的问题

    在把这个博客做好后,上传到nginx服务器上却出现问题. 首先是wordpress官方的伪静态是通过.htaccess实现的,但nginx并不支持.htaccess,无奈只好在网上找到wordpres ...

  3. python 类成员函数

    http://cowboy.1988.blog.163.com/blog/static/75105798201091141521583/ 这篇文章总结的非常好 主要注意的地方是 1,在类内调用成员函数 ...

  4. 243. Shortest Word Distance

    题目: Given a list of words and two words word1 and word2, return the shortest distance between these ...

  5. 63. Unique Paths II

    题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...

  6. Android handler.obtainMessage()

    在handler.obtainMessage()的参数是这样写的: Message android.os.Handler.obtainMessage(int what, int arg1, int a ...

  7. Eclipse groovy in action

    Eclipse :Version: Juno Service Release 2GrEclipse plugins:http://dist.springsource.org/release/GRECL ...

  8. 利用 img 和 script 发送跨域请求

    利用img.src可以发送http请求,但是发送http请求不是img.src的真正用意. 同样,用script.src去请求jsonp格式的接口数据也不是script元素的最初设计用途. 但是这些歪 ...

  9. tomcat作为windows服务启动失败解决方法

    再使用如下方法注册windows服务时,出现问题: set CATALINA_BASE=E:\tomcat\tomcat-web-server set CATALINA_HOME=E:\tomcat\ ...

  10. Linux/Centos下清理内存和Cache方法

    Linux/Centos下释放内存和缓存方法 $ free -m 运行sync将dirty的内容写回硬盘$ sync 通过修改proc系统的drop_caches清理free的cache$ echo ...