单词游戏
2011-10-18 16:28
190 查看
单词游戏
【问题描述】
Io和Ao在玩一个单词游戏。
他们轮流说出一个仅包含元音字母的单词,并且后一个单词的第一个字母必须与前一个单词的最后一个字母一致。
游戏可以从任何一个单词开始。
任何单词禁止说两遍,游戏中只能使用给定词典中含有的单词。
游戏的复杂度定义为游戏中所使用的单词长度总和。
编写程序,求出使用一本给定的词典来玩这个游戏所能达到的游戏最大可能复杂度。
【输入】
输入文件的第一行,表示一个自然数N(1≤N≤16),N表示一本字典中包含的单词数量以下的每一行包含字典中的一个单词,每一个单词是由字母A、E、I、O和U组成的一个字符串,每个单词的长度将小于等于100,所有的单词是不一样的。
【输出】
输出文件仅有一行,表示该游戏的最大可能复杂度。
【样例】
words.in words.out
5 16
IOO
IUUO
AI
OIOOI
AOOI
=============================
一道搜索:
不过要加2个剪枝才可全部过完
1.判断当前单词是否可以和其他单词组合
2.总长度是否达到最长,达到最长就退出。
-------------------------------------------------------
刚开始只想到了第2个剪枝.
其实现在想想要结合第一个剪枝第二个剪枝才能发挥最大的作用
不过还是有一些侥幸的思想在里面。
------------------------------------------------------------------------------------
正解应该为欧拉路..
================================================
源程序名 words.???(pas, c, cpp) 可执行文件名 words.exe 输入文件名 words.in 输出文件名 words.out |
Io和Ao在玩一个单词游戏。
他们轮流说出一个仅包含元音字母的单词,并且后一个单词的第一个字母必须与前一个单词的最后一个字母一致。
游戏可以从任何一个单词开始。
任何单词禁止说两遍,游戏中只能使用给定词典中含有的单词。
游戏的复杂度定义为游戏中所使用的单词长度总和。
编写程序,求出使用一本给定的词典来玩这个游戏所能达到的游戏最大可能复杂度。
【输入】
输入文件的第一行,表示一个自然数N(1≤N≤16),N表示一本字典中包含的单词数量以下的每一行包含字典中的一个单词,每一个单词是由字母A、E、I、O和U组成的一个字符串,每个单词的长度将小于等于100,所有的单词是不一样的。
【输出】
输出文件仅有一行,表示该游戏的最大可能复杂度。
【样例】
words.in words.out
5 16
IOO
IUUO
AI
OIOOI
AOOI
=============================
一道搜索:
不过要加2个剪枝才可全部过完
1.判断当前单词是否可以和其他单词组合
2.总长度是否达到最长,达到最长就退出。
-------------------------------------------------------
刚开始只想到了第2个剪枝.
其实现在想想要结合第一个剪枝第二个剪枝才能发挥最大的作用
不过还是有一些侥幸的思想在里面。
------------------------------------------------------------------------------------
正解应该为欧拉路..
================================================
type node=record h,t:char; v:longint; end; var n:longint; nt:longint; st:string; word:array[1..16]of node; //h,t:array[1..6]of longint; ans:longint; f:array[1..16]of boolean; procedure init; begin assign(input,'words.in'); assign(output,'words.out'); reset(input); rewrite(output); end; procedure terminate; begin close(input); close(output); halt; end; {function num(ch:char):longint; begin case ch of 'A': exit(1); 'E': exit(2); 'I': exit(3); 'O': exit(5); 'U': exit(6); end; end; } procedure dfs(t,tot:longint;ch:char); var i:longint; begin if t>nt then begin writeln(ans); terminate; end; for i:=1 to n do if (f[i])and ((ch='*')or(ch=word[i].h)) then begin f[i]:=false; if ans<tot+word[i].v then ans:=tot+word[i].v; dfs(t+1,tot+word[i].v,word[i].t); f[i]:=true; end; end; procedure main; var i,j:longint; begin readln(n); fillchar(f,sizeof(f),false); for i:=1 to n do begin readln(st); word[i].h:=st[1]; word[i].t:=st[length(st)]; word[i].v:=length(st); end; for i:=1 to n do for j:=1 to n do if i<>j then begin if word[i].t=word[j].h then begin f[i]:=true; f[j]:=true; end; end; nt:=n; ans:=0; for i:=1 to n do if not f[i] then begin dec(nt); if ans<word[i].v then ans:=word[i].v; end; dfs(1,0,'*'); writeln(ans); end; begin init; main; terminate; end.
相关文章推荐
- “单词竞猜游戏之管理员端”补充版
- 洛谷 P1278 单词游戏
- “单词竞猜游戏之管理员端”补充版
- 单词游戏
- 吴昊品游戏核心算法 Round 17(补遗篇) —— 单词游戏(前篇)
- P1278 单词游戏
- Yii Framework 开发教程(4) Hangman 猜单词游戏实例
- 单词搜索迷宫游戏
- 洛谷P1278 单词游戏
- 英语单词拼写游戏开发纪录
- 1066: 单词游戏(game)
- php猜单词游戏
- 转一个游戏里用到的英文单词
- 用js+html+css+txt做的记单词游戏(妈妈再也不用担心我的学习~)
- [itint5]单词游戏
- 字谜游戏,寻找字符矩阵中行、列、对角线方向的包含的所有单词
- 19个在“权利的游戏“中意思完全不同的单词
- P1278 单词游戏
- 【单词游戏】解题报告
- [各种面试题] 单词游戏