UVALive 4763
一开始,没敢写,感觉会超时。。。其实就是暴力搜索。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的更多相关文章
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
随机推荐
- linux服务器下发送邮件
系统管理人员经常会遇到对于设备或者任务的预警与通知,通常情况有发送短信.邮件等方式.发送短信一般来说需要有短信猫(硬件)或者调用libfetion给飞信用户发送.本文介绍几种简单的发送邮件的方式. 本 ...
- 函数执行到return就结束了
遇到return,函数就结束了,不会往下执行 测试: class User { String name; int age; boolean fun1(int i){ if(i==1){ return ...
- C# 任意类型数据转JSON格式(转)
HOT SUMMER 每天都是不一样,积极的去感受生活 C# 任意类型数据转JSON格式 /// <summary> /// List转成json /// </summary> ...
- MyEclipse开发WebService教程
. 创建一个 webService 工程. 2. 创建一个普通 Java 类 3. 创建 webService 服务端 HelloJaxwsDelegate.java 的源代码如下: 4. 导 ...
- firebug的使用方法和技巧(web开发调试工具)
Firebug是firefox下的一个插件,能够调试所有网站语言,如Html,Css等,但FireBug最吸引我的就是javascript调试功 能,使用起来非常方便,而且在各种浏览器下都能使用(IE ...
- cmd打开git
一旦你的git安装成功,而且在安装是没有选择可以使用cmd黑窗口来打开,那么你再来设置会很麻烦,我表示不会. 今天分享下同事分享给我的一个不错的方法. 这个方法依赖一个 Dos 文件(.bat文件), ...
- gulp自动刷新插件
gulp自动刷新的插件很多,但是感觉最好用的还是 browser-sync 插件.如果不想用命令行,也可以使用 browser-sync界面工具 先安装 browser-sync 插件: npm in ...
- zoj 3778 Talented Chef(思维题)
题目 题意:一个人可以在一分钟同时进行m道菜的一个步骤,共有n道菜,每道菜各有xi个步骤,求做完的最短时间. 思路:一道很水的思维题, 根本不需要去 考虑模拟过程 以及先做那道菜(比赛的时候就是这么考 ...
- bzoj2242: [SDOI2011]计算器 && BSGS 算法
BSGS算法 给定y.z.p,计算满足yx mod p=z的最小非负整数x.p为质数(没法写数学公式,以下内容用心去感受吧) 设 x = i*m + j. 则 y^(j)≡z∗y^(-i*m)) (m ...
- .net项目的svn Global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_S ...