【字典树模板(数组实现)】HDU 1251 统计难题
来源:互联网 发布:哈达迪nba数据 编辑:程序博客网 时间:2024/05/03 12:18
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1251
#include<cstdio>#include<cstring>#define NODE 1000005int next[NODE][26];//数组建树int v[NODE];//相同前缀个数int node;//节点个数void init(){ node=1; memset(next[0],0,sizeof(next[0]));}void add(char *str){ int len=strlen(str); int i; int cur=0,k; for(i=0;i<len;++i){ k=str[i]-'a'; if(next[cur][k]==0){ memset(next[node],0,sizeof(next[node])); v[node]=0; next[cur][k]=node++; } v[next[cur][k]]++; cur=next[cur][k]; }} int cal(char *str){ int i,k,cur=0; int len=strlen(str); for(i=0;i<len;++i){ k=str[i]-'a'; if(next[cur][k]) cur=next[cur][k]; else return 0; } return v[cur];}int main(){ int i; char str[20]; init(); while(1){ gets(str); if(str[0]=='\0')break; add(str); } while(scanf("%s",str)!=EOF){ printf("%d\n",cal(str)); } return 0;}
0 0
- 【字典树模板(数组实现)】HDU 1251 统计难题
- HDU 1251 (统计难题) 字典树模板&&map实现
- HDU 1251 统计难题(字典树模板)
- HDU - 1251 统计难题(字典树模板题)
- HDU 1251 统计难题 【动态存储+字典树(模板)】
- HDU 1251 统计难题(字典树模板)
- Hdu 1251-统计难题(字典树模板题)
- hdu 1251 统计难题 字典树解释 +字典树模板
- HDU - 1251 统计难题(字典数模板)
- HDU 1251统计难题(字典树)
- hdu 1251 统计难题(字典树)
- hdu 1251 统计难题(字典树)
- hdu 1251 统计难题(字典树)
- hdu 1251 统计难题 (字典树)
- hdu 1251 统计难题(字典树)
- HDU 1251 统计难题(字典树)
- HDU 1251 统计难题(字典树)
- HDU 1251 统计难题(字典树)
- 投降?_拉斯多尼一瞬间就愣住了!_芒特拉斯这是什么意思?{随
- STM32 USB使用——下位机
- Android应用程序进程启动过程的源代码分析
- 到底什么是MVC
- Flex4 导入Excel文件示例
- 【字典树模板(数组实现)】HDU 1251 统计难题
- HDU 2444 The Accomodation of Students二分图判定和匈牙利算法
- Java 多线程断点下载(面向对象)
- C语言编程规范(排版)
- freemaker生成数据文件
- 聚米移动广告平台——广告主不可错过的投放选择
- 网络调试助手 工具
- Connected to the target VM,address:'localhost:9120',transport:'socket'
- SAP中修改Z Report时,开发系统和程序的初始系统不一致的问题