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 ...
随机推荐
- TCoolMemo
我们先起个名字叫做TCoolMemo.以上篇已经讲了很多组件的技术,这里就只说出几个重点.其余不多说了. 首先,该Memo从CustomMemo继承,它有这样外观:属于平面的,边框是可以设置颜色的线, ...
- Larave 多图片上传
首先使用Dropzone.js前端组件 {{ HTML::style('css/basic.css');}} {{ HTML::script('js/dropzone.js') }} form部分只需 ...
- *像word一样编辑复杂的文本:SpannableString 样式详介
简介: 使用android.text.Spanned; android.text.SpannableString; android.text.SpannableStringBuilder; 和 and ...
- Android Studio修改包名和applicationId的方法
背景: 如果新做的项目跟以前做的某一个项目十分相似,那么一个简单的方法就是把原来项目拷贝一份,然后修改代码,但是这样包名还是原来项目的包名,还有如果想在同一台手机上同时安装新做的app和原来的app会 ...
- sdut 2847 Monitor (思维题)
题目 题意:给定a, b, x, y; 求使c, d; 使c:d = x :y; 且c<=a, d<=b, 而且c, d尽量大. 先求最小倍数, 再用最小倍数乘 x, y; #inclu ...
- PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different 2012-04-11 13:01
启动PL/SQL Developer 报字符编码不一致错误 Database character set (AL32UTF8) and Client character set (ZHS16GBK) ...
- bzoj1266: [AHOI2006]上学路线route
最短路+最小割 首先如何使最短路变长?就是要每一条最短路都割一条边. 我们求出每个点到点1和点n的距离,就可以知道哪些边在最短路上(一开始没有想到求到0和n的距离,想用floyd,但是n=500,怕超 ...
- NSAutoReleasePool
做iPhone应用开发已经2年多了, 但一些基础的概念性问题只是大致了解, 脑袋中有个模糊的概念. 虽然对平时工作开发没什么影响, 不过时间长了, 心里总是有点虚. 所以从现在开始, 每当我遇到一个模 ...
- BZOJ2482: [Spoj1557] Can you answer these queries II
题解: 从没见过这么XXX的线段树啊... T_T 我们考虑离线做,按1-n一个一个插入,并且维护区间[ j,i](i为当前插入的数)j<i的最优值. 但这个最优值!!! 我们要保存历史的最优值 ...
- Java Web编程的主要组件技术——JSP
参考书籍:<J2EE开源编程精要15讲> JSP(Java Server Page)页面由HTML代码和嵌入其中的Java代码组成. 简单的JSP页面如: <html> < ...