[字典树] hdu 1800 fly to the mar

这篇博客主要介绍了如何利用字典树数据结构解决HDU 1800题目,重点在于处理单调序列的众数问题。博主首先尝试了直接使用map的方法,但因效率低下导致超时。随后采用字典树实现,注意处理数字字符串时要去掉前导0,并在遇到0时保留一个。通过DFS遍历字典树获取最大计数。
摘要由CSDN通过智能技术生成
/**
[字典树] 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 -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值