先上题目

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

2

TNXO
AAEI
IOSR
BFRH
8
TAXES
RISE
ANNEX
BOAT
OATS
FROSH
HAT
TRASH FNEI
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就出结果。 上代码:
 #include <stdio.h>
#include <string.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std; map<string,int> M;
char s[][],c[];
bool mark[][]; bool dfs(int i,int j,int n)
{
if(i< || j<) return ;
if(mark[i][j]) return ;
if(s[i][j]==c[n])
{
if(c[n+]=='\0') return ;
mark[i][j]=;
if(dfs(i-,j-,n+)) return ; if(dfs(i-,j,n+)) return ; if(dfs(i-,j+,n+)) return ;
if(dfs(i,j-,n+)) return ; if(dfs(i,j+,n+)) return ;
if(dfs(i+,j-,n+)) return ; if(dfs(i+,j,n+)) return ; if(dfs(i+,j+,n+)) return ;
mark[i][j]=;
}
return ; } bool check()
{
int i,j;
for(i=;i<;i++)
{
for(j=;j<;j++)
{
if(s[i][j]==c[])
{
memset(mark,,sizeof(mark));
if(dfs(i,j,)) return ;
}
}
}
return ;
} int main()
{
int m,t,i,j,maxn,da,k;
//freopen("data.txt","r",stdin);
scanf("%d",&t);
for(k=;k<=t;k++)
{
M.clear();
memset(s,,sizeof(s));
for(i=;i<;i++)
{
scanf("%s",s[i]);
}
scanf("%d",&m);
maxn=;
for(j=;j<m;j++)
{
scanf("%s",c);
if(M.count(c)>) continue;
M[c]=;
if(!check()) continue;
da=strlen(c);
if(da<) continue;
switch(da)
{
case :
case : da=;break;
case : da=;break;
case : da=;break;
case : da=;break;
default :da=;
}
maxn=da+maxn;
}
printf("Score for Boggle game #%d: %d\n",k,maxn);
}
return ;
}

11283

												

UVa - 11283 - PLAYING BOGGLE的更多相关文章

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

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

  2. [uva] 10067 - Playing with Wheels

    10067 - Playing with Wheels 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Ite ...

  3. uva 1482 - Playing With Stones

    对于组合游戏的题: 首先把问题建模成NIM等经典的组合游戏模型: 然后打表找出,或者推出SG函数值: 最后再利用SG定理判断是否必胜必败状态: #include<cstdio> #defi ...

  4. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

  5. 09_Sum游戏(UVa 10891 Game of Sum)

    问题来源:刘汝佳<算法竞赛入门经典--训练指南> P67 例题28: 问题描述:有一个长度为n的整数序列,两个游戏者A和B轮流取数,A先取,每次可以从左端或者右端取一个或多个数,但不能两端 ...

  6. UVA 1292 十二 Strategic game

    Strategic game Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Sta ...

  7. 【UVa 10881】Piotr's Ants

    Piotr's Ants Porsition:Uva 10881 白书P9 中文改编题:[T^T][FJUT]第二届新生赛真S题地震了 "One thing is for certain: ...

  8. 容斥原理--计算错排的方案数 UVA 10497

    错排问题是一种特殊的排列问题. 模型:把n个元素依次标上1,2,3.......n,求每一个元素都不在自己位置的排列数. 运用容斥原理,我们有两种解决方法: 1. 总的排列方法有A(n,n),即n!, ...

  9. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

随机推荐

  1. C++顺序表(模板总结)

    C++顺序表(模板总结) 总结: 1.模板类的实质是什么:让程序员写出和类型无关的代码 2.模板的对象时什么:方法或者类 3.是对类中的一系列操作,提供一个不固定数据类型的方法 用模板做的类的时候要指 ...

  2. C# 你什么让程序员寂寞成酱紫 (男生版 娱乐中学习 抽象类 接口 继承 实现方法 )

    你什么让程序员寂寞成酱紫 (男生版 娱乐中学习 抽象类 接口 继承 实现方法 )   一个家庭 相当于 一个空间,这个空间里 有 很多元素,比如 爱,爱这个抽象事物,可能有很多动作,接吻.交流,对于一 ...

  3. 杂项-TMod:常见错误

    ylbtech-杂项-TMod:常见错误 1.返回顶部 1. 1.1. {Template Error} TypeError: dateDiff is not a function at Array. ...

  4. 442C

    贪心 感觉思路很奥妙 首先我们把那些比两边小的数删掉,因为不删的话两边的数就会选这个数,这样就成了先上升后下降的序列,很明显除了第一第二大的数都能选,然后统计就好了. #include<bits ...

  5. PCB决策引擎:多维决策表转决策树

    准备设计一个PCB使用的决策引擎,需要用到决策表,而单维决策表不能满足业务要求, 这里主要是为了实现:用户编辑的是决策表,实际底层存储的是树结构,树的的各个节点挂上业务决策逻辑. 这里将多维决策表转决 ...

  6. bzoj 3172 单词

    3172: [Tjoi2013]单词 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 3937  Solved: 1912[Submit][Status ...

  7. 有关于dict(字典)的特性与操作方法

    有关于dict(字典)的特性与操作方法 1.字典的特性 语法: dic = {key1 : value1,key2 : value2,key3 : value3............} 注:字典中k ...

  8. 修改CAS源码是的基于DB的认证方式配置更灵活

    最近在做CAS配置的时候,遇到了数据源不提供密码等数据的情况下,怎样实现密码输入认证呢? 第一步:新建Java项目,根据假面算法生成CAS加密工具 出于保密需要不提供自定义的加密工具,在您的实际项目中 ...

  9. C - Tram

    Problem description Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n i ...

  10. webApi上传服务,可重命名,可创建文件夹

    webApi上传服务,根据FileName重命名,根据Path创建文件夹 /// <summary> /// 上传文件 /// </summary> /// <retur ...