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

4 10 20 30 04 5 2 3 4 3 4
1 2
/*士兵要学骑扫帚。每个士兵有一个level,
level高的能在同一把扫帚上教level低的怎么骑。
一个人最多有一个老师,一个学生。也可以没有。
给n个士兵的level值,问最少需要多少扫帚。*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct node
{
    node *next[10];
    int Count;
    node()
    {
        for (int i=0; i<10; i++)
            next[i]=NULL;
        Count=0;
    }
};
int Max;
node *p,*root;
void Insert(char *s)
{
    p=root;
    for (int i=0; s[i]; i++)
    {
        int k=s[i]-'0';
        if (p->next[k]==NULL)
            p->next[k]=new node();
        p=p->next[k];
    }
    p->Count++;
    if (p->Count>Max)
        Max=p->Count;
}
/*void Search(int *s)
{
    p=root;
    for (int i=0;i<n;i++)
    {
        int k=s[i]-'0';
        if (p->next[k]==NULL])
            return ;
        p=p->next[k];
    }
}*/
int main()
{
    int n,j;
    char ch[40];
    while (~scanf("%d",&n))
    {
        root=new node();
        Max=0;
        for (int i=0; i<n; i++)
        {
            scanf("%s",ch);
            int len=strlen(ch);
            for (j=0; j<len; j++)
            {
                if (ch[j]!='0')
                    break;
            }
            Insert(ch+j);
        }
        printf ("%d\n",Max);
    }
    return 0;
}
hdu1800 Flying to the Mars(字典树)
原文:http://blog.csdn.net/qiqi_skystar/article/details/47950707