一开始,没敢写,感觉会超时。。。其实就是暴力搜索。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. yum工具介绍

    当你的linux处于联网状态时,yum工具能够非常方便的在Linux上安装各种软件.补丁等等,而且最重要的一点是完全不用管包的依赖关系.只需要简单的指定你要安装的软件名称,其他工作几乎都交给yum了, ...

  2. [iOS]iPhone利用<极光推送>实现远程推送

    准备: 1. 一个Xcode工程 2. 开发者账号 3. 真机 (重要,模拟器无法进行远程推送,因为模拟器没有UDID) 第一步:绑定工程的Bundle Identifer 首先当然要登录https: ...

  3. redhat 新装后不能联网

    1.ifconfig查看是否有ip地址,如果没有就配置,命令如下: [root@redhat ~]# system-config-network 设置DHCP 为 [*] [ok]后,重新ifconf ...

  4. Javascript如何判断一个变量是数字类型?

    isNaN()不能判断一个变量是否为数字类型,isNaN(123)值为false,isNaN('123')值也为false.isNaN() 的实际作用跟它的名字isNaN并不一致,isNaN(NaN) ...

  5. NDK xxxxx could not be resolved解决方法

    Type '*****' could not be resolved Method '******' could not be resolved     问题解决   以下为未尝试方法,如果上面方法解 ...

  6. How to upgrade gcc using apt-get ?

    在toolchain/test下已经有打包好的gcc,版本有4.x.5.0.6.0等,用这个PPA升级gcc就可以啦! 首先添加ppa到库: 1 sudo add-apt-repository ppa ...

  7. HDU 4565 So Easy!(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...

  8. inline-block在ie6中的经典bug

    众所周知,给元素设置 inline-block ,可以让ie下的元素出发layout:1. 但是,当给元素设置 inline-block 后,在另外一个class 样式(非设置inline-block ...

  9. 严重: Catalina.stop: java.net.ConnectException: Connection refused: connect

    原因: 1.连接被拒绝,关闭的时候报错.是不是已经关闭了,你又关闭,他当然找不到了. 2.连接被拒绝有可能是服务端连接数到达最高了 3.服务器拒绝连接,ip地址是否写对,端口号正确与否,网络是否通畅, ...

  10. USACO 2006 November Gold

    POJ 3253 Fence Repair STL堆操作 我想说,STL里堆是我目前见到最蛋疼的操作. #include <cstdio> #include <cstring> ...