HRBUST1213 单词接龙 2017-03-06 15:53 67人阅读 评论(0) 收藏
对于每组测试数据,第一行为一个单独的整数n (n<=20)表示单词数,以下n 行每行有一个单词,输入的最后一行为一个单个字符,表示“龙”开头的字母。你可以假定以此字母开头的“龙”一定存在.
at
touch
cheat
choose
tact
a
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
using namespace std; #define inf 0x3f3f3f3f int edge[25][25];
char s[25][10005];
int val[25];
int vis[25];
int mx;
int n; void dfs(int num,int len)
{
mx=max(mx,len);
for(int i=0; i<n; i++)
{
if(vis[i]<2&&edge[num][i]!=inf)
{
vis[i]++;
dfs(i,len+val[i]-edge[num][i]);
vis[i]--;
}
}
} int main()
{ while(~scanf("%d",&n))
{
for(int i=0; i<=n; i++)
scanf("%s",&s[i]);
for(int i=0; i<n; i++)
{
val[i]=strlen(s[i]);
}
memset(edge,inf,sizeof edge);
memset(vis,0,sizeof vis);
for(int i=0; i<n; i++)
{
if(s[i][0]==s[n][0])
edge[n][i]=0;
}
for(int i=0; i<n; i++)
{ for(int j=0; j<n; j++)
{
int a=strlen(s[i]);
int b=strlen(s[j]);
int l=1;
int r=0;
while(l<a)
{
r=0;
int fla=1;
if(s[i][l]==s[j][r])
{
if(l+b<a)
{
l++;
continue;
} for(; l+r<a; r++)
{
if(s[i][l+r]!=s[j][r])
{
fla=0;
}
}
if(fla==1)
edge[i][j]=min(edge[i][j],r);
} l++;
} } }
for(int i=0; i<n; i++)
{
if(s[i][0]==s[n][0])
edge[n][i]=0;
} /* for(int i=0; i<=n; i++)
{
for(int j=0; j<=n; j++)
{
printf("%d ",edge[i][j]);
}
printf("\n");
}*/
mx=0;
dfs(n,0);
printf("%d\n",mx);
} return 0;
}
HRBUST1213 单词接龙 2017-03-06 15:53 67人阅读 评论(0) 收藏的更多相关文章
- 搜索 基础 AC 2014-01-14 15:53 170人阅读 评论(0) 收藏
题目网址:http://haut.openjudge.cn/xiyoulianxi1/1/ 1:晶矿的个数 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 ...
- Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏
Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...
- Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏
Gold Coins Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21767 Accepted: 13641 Desc ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- 苹果应用商店AppStore审核中文指南 分类: ios相关 app相关 2015-07-27 15:33 84人阅读 评论(0) 收藏
目录 1. 条款与条件 2. 功能 3. 元数据.评级与排名 4. 位置 5. 推送通知 6. 游戏中心 7. 广告 8. 商标与商业外观 9. 媒体内容 10. 用户界面 11. 购买与货币 12. ...
- Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
- Codeforces777D Cloud of Hashtags 2017-05-04 18:06 67人阅读 评论(0) 收藏
D. Cloud of Hashtags time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- hdu1158 Employment Planning 2016-09-11 15:14 33人阅读 评论(0) 收藏
Employment Planning Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 初学者必知的Python中优雅的用法 分类: Python 2015-05-11 15:02 782人阅读 评论(0) 收藏
本文由 伯乐在线 - 淘小米 翻译,Daetalus 校稿.未经许可,禁止转载!英文出处:freepythontips.wordpress.com.欢迎加入翻译小组. Hi 朋友们.由于我最近都比较忙 ...
随机推荐
- CentOS之NTP服务器配置
本文使用CentOS 6.5作为搭建环境 一.服务器端配置 1.安装所需软件包 yum -y install ntp ntpdate---------------------------------- ...
- memcached内存管理机制分析
memached是高性能分布式内存对象系统,通过在内存中存储数据对象来减少对磁盘的数据读取次数,提高服务速度. 从业务需求出发.我们通过一条命令(如set)将一条键值对(key,value)插入mem ...
- Chrome JS断点调试技巧
Chrome调试折腾记_(2)JS断点调试技巧 技巧一:格式化压缩代码 技巧二:快速跳转到某个断点的位置 技巧三:查看断点内部的作用范围[很实用] 技巧4:监听事件断点 技巧5:DOM及 XHR监听跳 ...
- Android ListView根据项数的大小自动改变高度
第一种:按照listview的项数确定高度 ListAdapter listAdapter = listView.getAdapter(); if (listAdapter == null) ...
- JavaScript之深拷贝&浅拷贝
深拷贝&浅拷贝,说起来都明白,但是说不出所以然.今天就系统的整理下思绪,一点点的将其分析出所以然 废话不多说 浅拷贝 简单的说就是一个值引用,学生时代接触过编程的人都应该了解过指针,浅拷贝可以 ...
- Linux内核优化(未注释)
Nginx代理服务内核优化 # Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disab ...
- python 爬预警没解析前的
- 「小程序JAVA实战」小程序的微信api菜单操作(67)
转自:https://idig8.com/2018/09/25/xiaochengxujavashizhanxiaochengxudeweixinapicaidancaozuo66/ 菜单按钮的介绍, ...
- JAVA获取txt文件内容
JAVA 读取txt文件内容 通常,我们可以直接通过文件流来读取txt文件的内容,但有时可能会出现乱码!此时只要设置一下文件字符编码即可. public class txttest { /** * 读 ...
- IOS上架截屏 屏幕快照
IOS上架截屏,屏幕快照,4种屏幕尺寸,每种尺寸5张软件功能截图. 大小等于对应设备的屏幕的像素大小.使用模拟器,command +s截图就可以了虚拟机里的手机截屏就保存在mac 桌面上了.jpg,p ...