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. swagger ui 值类型形参加文字注释

    例: @ApiImplicitParams({ @ApiImplicitParam(paramType = "query", name = "indexCondition ...

  2. 自动备份Mysql数据库脚本

    [root@bogon ~]# cat auto_backup_mysql.sh #!/bin/bash #auto backup mysql db #by authors wugk #define ...

  3. NET实现RSA AES DES 字符串 加密解密以及SHA1 MD5加密

    本文列举了    数据加密算法(Data Encryption Algorithm,DEA) 密码学中的高级加密标准(Advanced EncryptionStandard,AES)RSA公钥加密算法 ...

  4. WPF扩展标记X:STATIC

    原文:WPF扩展标记X:STATIC public class XStaic     {         public static string Content = "确定"; ...

  5. 图像滤镜艺术---(Sketch Filter)素描滤镜

    原文:图像滤镜艺术---(Sketch Filter)素描滤镜 (Sketch Filter)素描滤镜 素描滤镜的实现方法比较简单,这里我们直接写出算法过程如下: 1,对原图S进行去色命令得到灰度图A ...

  6. dotnet core 跨平台编译发布

    vs2017 建立的项目,在项目目录 ,执行 dotnet publish -r ubuntu.15.04-x64 dotnet publish -r linux-x64 dotnet publish ...

  7. C#高性能大容量SOCKET并发(零):代码结构说明

    原文:C#高性能大容量SOCKET并发(零):代码结构说明 C#版完成端口具有以下特点: 连接在线管理(提供在线连接维护,连接会话管理,数据接收,连接断开等相关事件跟踪): 发送数据智能合并(组件会根 ...

  8. Linux下的帮助命令

    内建命令,外部命令,命令别名:使用:type 命令名,查看 内建命令是shell一部分,一开始就加载进内存,程序一般简单:外部命令反之 2.  帮助命令的使用 内建命令:help 命令名:外部命令:命 ...

  9. Elasticsearch教程(一)简介与安装

    简单概念 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearch是用Java开发的,并作为 ...

  10. Standard C 语言标准函数库速查(彩色的函数列表,十分清楚)

    Standard C 语言标准函数库速查 (Cheat Sheet) wcstombs 函数说明 #include <stdlib.h> size_t mbstowcs(wchar_t * ...