先上题目

Problem F

PLAYING BOGGLE

Boggle® is a classic word game played on a 4 by 4 grid of letters. The letter grid is randomly generated by shaking 16 cubes labeled with a distribution of letters similar to that found in English words. Players try to find words hidden within the grid.

Words are formed from letters that adjoin horizontally, vertically, or diagonally. However, no letter may be used more than once within a single word.

An example Boggle® letter grid, showing the formation of the words "taxes" and "rise".

The score awarded for a word depends on its length, with longer words being worth more points. Exact point values are shown in the table below. A word is only ever scored once, even if it appears multiple times in the grid.

No. of letters: 3 4 5 6 7 8 or more
Points: 1 1 2 3 5 11

In this problem, your task is to write a program that plays Boggle®. Given a letter grid and a dictionary of words, you are to calculate the total score of all the words in the dictionary that can be found in the grid.

Input

The first line of the input file contains a number N, the number of Boggle® games that follow.

Each Boggle® game begins with 16 capital letters arranged in a 4 by 4 grid, representing the board configuration for that game. A blank line always precedes the letter grid. Following the letter grid is a single number M (1 ≤ M ≤ 100), the number of words in your dictionary for that game. The next M lines contain the dictionary words, one per line, in no particular order. Each word consists of between 3 and 16 capital letters. No single word will appear in the dictionary more than once for a given Boggle® game.

Output

For each Boggle® game in the input, your program should output the total score for that game. Follow the format given in the sample output.

Sample Input

2TNXO
AAEI
IOSR
BFRH
8
TAXES
RISE
ANNEX
BOAT
OATS
FROSH
HAT
TRASHFNEI
OBCN
EERI
VSIR
1
BEER

Output for the Sample Input

Score for Boggle game #1: 6
Score for Boggle game #2: 1

  排位赛时这一题没有做出来,因为题意理解错了= =,以为是找到一个单词以后,这个单词用过的格子全部都不可以再用了,但其实不是这样。这一题的题意是不同长度的单词有不同的得分,给出字符矩阵让你在其中找一系列单词,找到一个单词就得到特定的分数,同一个单词得分只计算一次,当然,也有可能里面找不到给出的单词,如果是这样就加0分,最后问你可以得到多少得分。由于这一题给的矩阵是4*4,完全就是一个裸的dfs,只需跑一边dfs就出结果。

上代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <map>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7
 8 map<string,int> M;
 9 char s[5][5],c[20];
10 bool mark[5][5];
11
12 bool dfs(int i,int j,int n)
13 {
14     if(i<0 || j<0) return 0;
15     if(mark[i][j]) return 0;
16     if(s[i][j]==c[n])
17     {
18         if(c[n+1]=='\0') return 1;
19         mark[i][j]=1;
20         if(dfs(i-1,j-1,n+1)) return 1;  if(dfs(i-1,j,n+1)) return 1;  if(dfs(i-1,j+1,n+1)) return 1;
21         if(dfs(i,j-1,n+1)) return 1;                                  if(dfs(i,j+1,n+1)) return 1;
22         if(dfs(i+1,j-1,n+1)) return 1;  if(dfs(i+1,j,n+1)) return 1;  if(dfs(i+1,j+1,n+1)) return 1;
23         mark[i][j]=0;
24     }
25     return 0;
26
27 }
28
29 bool check()
30 {
31     int i,j;
32     for(i=0;i<4;i++)
33     {
34         for(j=0;j<4;j++)
35         {
36             if(s[i][j]==c[0])
37             {
38                 memset(mark,0,sizeof(mark));
39                 if(dfs(i,j,0)) return 1;
40             }
41         }
42     }
43     return 0;
44 }
45
46 int main()
47 {
48     int m,t,i,j,maxn,da,k;
49     //freopen("data.txt","r",stdin);
50     scanf("%d",&t);
51     for(k=1;k<=t;k++)
52     {
53         M.clear();
54         memset(s,0,sizeof(s));
55         for(i=0;i<4;i++)
56         {
57             scanf("%s",s[i]);
58         }
59         scanf("%d",&m);
60         maxn=0;
61         for(j=0;j<m;j++)
62         {
63             scanf("%s",c);
64             if(M.count(c)>0) continue;
65             M[c]=1;
66             if(!check()) continue;
67             da=strlen(c);
68             if(da<3) continue;
69             switch(da)
70             {
71                 case 3:
72                 case 4: da=1;break;
73                 case 5: da=2;break;
74                 case 6: da=3;break;
75                 case 7: da=5;break;
76                 default :da=11;
77             }
78             maxn=da+maxn;
79         }
80         printf("Score for Boggle game #%d: %d\n",k,maxn);
81     }
82     return 0;
83 }

11283

转载于:https://www.cnblogs.com/sineatos/p/3221458.html

UVa - 11283 - PLAYING BOGGLE相关推荐

  1. UVA 1482 - Playing With Stones(SG打表规律)

    UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函 ...

  2. sicily题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  3. [sicily]部分题目分类

    sicily题目分类 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. ...

  4. Sicily 题目分类

    依照自己水平挑着做→ →~~ 1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 ...

  5. 编程题目分类(剪辑)

    1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代 ...

  6. UVa Problem 10067 Playing With Wheels (摆弄轮子)

    // Playing With Wheels (摆弄轮子) // PC/UVa IDs: 110902/10067, Popularity: C, Success rate: average Leve ...

  7. UVA 487 - Boggle Blitz

    回溯就可以了 #include <iostream> #include <algorithm> #include <memory.h> #include <c ...

  8. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  9. UVa 1225 Digit Counting 题解

    英文 Description Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts w ...

最新文章

  1. 【MATLAB】数据类型 ( 矩阵 | 随机数函数 | 生成矩阵 )
  2. “纯金”卫星,撞向我们的“蛋壳时代”
  3. android谷歌反地理,Android反向地理编码显示不出来!
  4. 利用服务端session保存用户信息
  5. 使用OpenRefine清洗数据实例
  6. FOXIT PDF EDITOR工具分割PDF
  7. 中国邮路算法(中国邮递员问题)(详细)
  8. [每日一氵]上古年代的 Visual Studio2015 安装
  9. 学校计算机比赛策划,学校计算机技能比赛活动策划方案
  10. 【源码】二进制非洲秃鹫优化算法
  11. 寻求持续发展 Criteo中国业务正式启动
  12. 中国十大垃圾软件网站
  13. cad展点kszd小程序_CAD坐标展点脚本文件-CAD坐标展点程序下载v2 官方版-西西软件下载...
  14. ffmpeg实现变速播放的两种方案
  15. matlab近红外光谱曲线,Matlab关于偏最小二乘法应用于近红外光谱分析的问题
  16. JAVA incept_关于Inception默认配置的一个坑
  17. 医院“移动”不起来软肋在数据安全?
  18. python爬虫能赚钱吗-个人利用Python爬虫技术怎么挣钱-10万被动收入
  19. obs源码分析【八】:显示器采集
  20. 总结一下:运维工程师面试的经历及面试相关问题

热门文章

  1. 真正的Windows XP SP2上海政府版
  2. 全网疯传!微信发原图暴露个人信息?微信高冷回应!真相来了...
  3. 《CornerNet: Detecting Objects as Paired Keypoints》之 corner pooling 解读
  4. 国产迪王耀全球(上)
  5. python- ASCII字符串转为16进制格式
  6. Android接收短信和发送短信
  7. JAVA系统之间通信方式总结
  8. 攻防世界-Crypto-Railfence
  9. freeMarker导出word带图片
  10. 微信小程序介绍、区别