`
peizhiinfo
  • 浏览: 1426328 次
文章分类
社区版块
存档分类
最新评论

Hdu-1251 统计难题

 
阅读更多

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251

解题思路:

字典树的典型应用——插入,查询。

1.插入时候,不是字母结束时将head->count++,而是遇到字母:

没出现过:初始化1,表明此次出现

出现过:count++

这样,head->count记录的就是从根结点到head结点的前缀出现的次数。

2.查询

返回单词结尾字母的count就是前缀出现的次数。

代码如下:



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics