UVA - 11283 《PLAYING BOGGLE》【DFS】
来源:互联网 发布:宝宝吃奶记录软件 编辑:程序博客网 时间:2024/06/14 05:23
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:345678 or morePoints:1123511In 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
2TNXOAAEIIOSRBFRH8TAXESRISEANNEXBOATOATSFROSHHATTRASHFNEIOBCNEERIVSIR1BEER
Output for the Sample Input
Score for Boggle game #1: 6Score for Boggle game #2: 1
#include<cstdio>#include<cmath>#include<cstring>char s[101];char Boggle[4][5];bool B[4][4];bool found;int DirectionX[8]={-1,-1,-1,0,1,1,1,0};int DirectionY[8]={-1,0,1,1,1,0,-1,-1};int count=0;void dfs(int a,int b,int c){ int pos=c+1; int l=strlen(s); if(pos==l) { found=1; if(l>=3)count+=1; if(l>=5)count+=1; if(l>=6)count+=1; if(l>=7)count+=2; if(l>=8)count+=6; } for(int i=0;i<8&&!found;i++) { int x=a+DirectionX[i]; int y=b+DirectionY[i]; if(x>=0&&x<4&&y>=0&&y<4&&!found&&!B[x][y]&&Boggle[x][y]==s[pos]) { B[x][y]=1; dfs(x,y,pos); B[x][y]=0; } }}int main(){ int T; scanf("%d",&T); for(int t=1;t<=T;t++) { int n; for(int i=0;i<4;i++)scanf("%s",&Boggle[i]); scanf("%d",&n); count=0; while(n--) { scanf("%s",&s); found=0; for(int i=0;i<4;i++)for(int j=0;j<4;j++)B[i][j]=0; for(int i=0;i<4;i++) for(int j=0;j<4&&!found;j++) if(Boggle[i][j]==s[0]) { B[i][j]=1; dfs(i,j,0); B[i][j]=0; } } printf("Score for Boggle game #%d: %d\n",t,count); } return 0;}
- UVA - 11283 《PLAYING BOGGLE》【DFS】
- DFS csu1719 Boggle
- UVA 487 - Boggle Blitz
- Boggle
- COJ 2498 - Boggle AC自动机+DFS
- UVa 10067 - Playing with Wheels
- UVA - 1482 Playing With Stones
- PC/UVa 110902/10067 Playing With Wheels
- uva 1482 - Playing With Stones(Nim游戏)
- "玲珑杯”ACM比赛 Round #8-D XJT Loves Boggle(dfs)
- Boggle记录
- 【DFS】UVA
- 【DFS】UVA
- UVa Problem 10067 Playing With Wheels (摆弄轮子)
- UVA 1482 - Playing With Stones (SG博弈)
- UVA 1482 - Playing With Stones(SG打表规律)
- UVA-1482 Playing With Stones(SG函数打表找规律)
- Boggle问题积累
- PopupWindow设置点击区域以外部分时自动消失
- 你要做哪一只苹果虫?(苹果定律,转给迷茫中的人们)
- I18N国际化
- OpenGL—渲染管线
- sql语句大全
- UVA - 11283 《PLAYING BOGGLE》【DFS】
- 如何自学3d游戏
- VS2005不能调试WinCE应用解决方法
- SGU 307: Cipher
- 让Windows Server 2008 + IIS 7+ ASP.NET 支持10万并发请求
- iOS和android游戏纹理优化和内存优化(cocos2d-x)
- uva572
- TPCC-UVA测试环境搭建与结果分析
- delphi内嵌汇编的符号类型