/**
[字典树] hdu 1800 fly to the mar
开始以为求出最多有多少个单调序列,这个真不会,发现是求众数。
先map了一下,直接tle了。
然后字典树,注意1,去掉前导0;2,如果是0,要保留一个。
*/
#include <stdio.h>
#include <string>
#include <string.h>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define N 3000
#define MAXN 100000
struct tireTree
{
int cnt;
tireTree *child[10];
}tt[MAXN],*spt;
void insert(char *s,tireTree *&rt)
{
int num,i;
tireTree *loc;
loc = rt;
for(i = 0; s[i]; ++i)
{
num = s[i] - '0';
if(loc -> child[num] == NULL)
loc -> child[num] = spt++;
loc = loc -> child[num];
}
loc -> cnt ++;
}
int maxx;
void dfs(tireTree *rt)
{
i
[字典树] hdu 1800 fly to the mar
最新推荐文章于 2020-05-09 10:07:54 发布
这篇博客主要介绍了如何利用字典树数据结构解决HDU 1800题目,重点在于处理单调序列的众数问题。博主首先尝试了直接使用map的方法,但因效率低下导致超时。随后采用字典树实现,注意处理数字字符串时要去掉前导0,并在遇到0时保留一个。通过DFS遍历字典树获取最大计数。
订阅专栏 解锁全文
9万+

被折叠的 条评论
为什么被折叠?



