http://www.ifrog.cc/acm/problem/1082

题意:给出的单词要在3*3矩阵里面相邻连续(相邻包括对角),如果不行就输出0,如果可行就输出对应长度的分数。

思路:爆搜,但是写砸了。处理一次状态的时候把vis[i][j]设成1,然后DFS。DFS完之后还要把vis[i][j]改成0,否则就会只搜一条路径了。QAQ。正解貌似是枚举所有的可行字符串丢到set里面。

 #include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iostream>
#include <stack>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
#define N 100010
#define INF 0x3f3f3f3f char mp[][], s[];
int vis[][], dx[] = {-, -, -, , , , , }, dy[] = {, , -, , -, , , -}, flag;
int mm[] = {, , , , , , , , , }; bool check(int x, int y, char c) {
if( <= x && x < && <= y && y < && mp[x][y] == c && !vis[x][y]) return true;
return false;
} void DFS(int x, int y, int now, int len) {
if(now >= len - ) { flag = ; return ; }
for(int i = ; i < ; i++) {
int nx = dx[i] + x, ny = dy[i] + y;
if(check(nx, ny, s[now+])) {
vis[nx][ny] = ;
DFS(nx, ny, now + , len);
vis[nx][ny] = ;
}
}
} int main()
{
int t;
scanf("%d", &t);
for(int cas = ; cas <= t; cas++) {
for(int i = ; i < ; i++) scanf("%s", mp[i]);
int q; scanf("%d", &q);
printf("Case #%d:\n", cas);
while(q--) {
scanf("%s", s);
int len = strlen(s); flag = ;
if(len >= )
for(int i = ; i < && !flag; i++) {
for(int j = ; j < && !flag; j++) {
if(mp[i][j] == s[]) {
memset(vis, , sizeof(vis));
vis[i][j] = ;
DFS(i, j, , len);
}
}
}
printf("%d\n", flag ? mm[len] : );
}
}
return ;
}

玲珑OJ 1082:XJT Loves Boggle(爆搜)的更多相关文章

  1. 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1817  Solved: 665[Submit][Status] ...

  2. POJ 1166 The Clocks (爆搜 || 高斯消元)

    题目链接 题意: 输入提供9个钟表的位置(钟表的位置只能是0点.3点.6点.9点,分别用0.1.2.3)表示.而题目又提供了9的步骤表示可以用来调正钟的位置,例如1 ABDE表示此步可以在第一.二.四 ...

  3. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  4. hdu5323 Solve this interesting problem(爆搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Solve this interesting problem Time Limit ...

  5. hdu4536-XCOM Enemy Unknown(爆搜)

    XCOM-Enemy Unknown是一款很好玩很经典的策略游戏. 在游戏中,由于未知的敌人--外星人入侵,你团结了世界各大国家进行抵抗.随着游戏进展,会有很多的外星人进攻事件.每次进攻外星人会选择3 ...

  6. poj1077 Eight【爆搜+Hash(脸题-_-b)】

    转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4298840.html   ---by 墨染之樱花 题目链接:http://poj.org/pr ...

  7. [NOIP2015] 斗地主 大爆搜

    考试的时候想了半天,实在是想不到解决的办法,感觉只能暴力..然后暴力也懒得打了,小数据模拟骗30分hhh 然而正解真的是暴力..大爆搜.. 然后我的内心拒绝改这道题(TAT) 不过在wcx大佬的帮助下 ...

  8. BZOJ 1207: [HNOI2004]打鼹鼠【妥妥的n^2爆搜,dp】

    1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 3259  Solved: 1564[Submit][Statu ...

  9. HDU 4403 A very hard Aoshu problem(dfs爆搜)

    http://acm.hdu.edu.cn/showproblem.php?pid=4403 题意: 给出一串数字,在里面添加一个等号和多个+号,使得等式成立,问有多少种不同的式子. 思路: 数据量比 ...

随机推荐

  1. VUE在开发环境下实现跨域

    1. 跨域设置 VUE项目的 config文件夹下index.js文件中修改 dev: proxyTable中的内容(默认是没有内容的): 添加内容: '/list': { target: 'http ...

  2. JDK源码阅读—ArrayList的实现

    1 继承结构图 ArrayList继承AbstractList,实现了List接口 2 构造函数 transient Object[] elementData; // 数组保存元素 private i ...

  3. QT pro 添加带空格的路径以及添加库文件的正确方法

    用这个:$$quote() 如何添加库?看下面添加mysql路径的例子: INCLUDEPATH += $$quote(C:\Program Files (x86)\MySQL\MySQL Serve ...

  4. sql xml 查询指定节点值,以及节点属性值

    SELECT   top 10  [HFMBDATA].query('(/Items/Item[@ID=''tbBryj''])').value('(//TextValue)[1]','nvarcha ...

  5. C++成员函数指针错误用法警示(成员函数指针与高性能的C++委托,三篇),附好多评论

    今天做一个成绩管理系统的并发引擎,用Qt做的,仿照QtConcurrent搞了个模板基类.这里为了隐藏细节,隔离变化,把并发的东西全部包含在模板基类中.子类只需注册需要并发执行的入口函数即可在单独线程 ...

  6. ORA-19625: error identifying file XXXXX

    在RMAN备份全库的时候,将归档日志一同进行备份,结果报如下错误,可以看到是无法获得对应归档日志的报错: RMAN: ========================================= ...

  7. 该内存不能read 或written数值 叙述(居然还有具体的讲究)

    该内存不能read 或written数值 叙述 0 0x0000 作业完成. 1 0x0001 不正确的函数. 2 0x0002 系统找不到指定的档案. 3 0x0003 系统找不到指定的路径. 4 ...

  8. Qt在Mac OS X下的编程环境搭建(配置Qt库和编译器,有图,很清楚)

    尊重作者,支持原创,如需转载,请附上原地址:http://blog.csdn.net/libaineu2004/article/details/46234079 在Mac OS X下使用Qt开发,需要 ...

  9. C#调用记事本并填写内容

    using System.Runtime.InteropServices; using System.Diagnostics;   [DllImport("User32.DLL") ...

  10. zyltimer与ZylIdleTimer

    http://www.zylsoft.com/zyltimer.htmhttp://www.zylsoft.com/products.htm