国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Flying to the Mars hdu1800 trie

2019-11-08 01:41:46
字體:
來源:轉載
供稿:網友

PRoblem Description


In the year 8888, the Earth is ruled by the PPF Empire . As the population growing , PPF needs to find more land for the newborns . Finally , PPF decides to attack Kscinow who ruling the Mars . Here the problem comes! How can the soldiers reach the Mars ? PPF convokes his soldiers and asks for their suggestions . “Rush … ” one soldier answers. “Shut up ! Do I have to remind you that there isn’t any road to the Mars from here!” PPF replies. “Fly !” another answers. PPF smiles :“Clever guy ! Although we haven’t got wings , I can buy some magic broomsticks from HARRY POTTER to help you .” Now , it’s time to learn to fly on a broomstick ! we assume that one soldier has one level number indicating his degree. The soldier who has a higher level could teach the lower , that is to say the former’s level > the latter’s . But the lower can’t teach the higher. One soldier can have only one teacher at most , certainly , having no teacher is also legal. Similarly one soldier can have only one student at most while having no student is also possible. Teacher can teach his student on the same broomstick .Certainly , all the soldier must have practiced on the broomstick before they fly to the Mars! Magic broomstick is expensive !So , can you help PPF to calculate the minimum number of the broomstick needed . For example : There are 5 soldiers (A B C D E)with level numbers : 2 4 5 6 4; One method : C could teach B; B could teach A; So , A B C are eligible to study on the same broomstick. D could teach E;So D E are eligible to study on the same broomstick; Using this method , we need 2 broomsticks. Another method: D could teach A; So A D are eligible to study on the same broomstick. C could teach B; So B C are eligible to study on the same broomstick. E with no teacher or student are eligible to study on one broomstick. Using the method ,we need 3 broomsticks. …… 這里寫圖片描述 After checking up all possible method, we found that 2 is the minimum number of broomsticks needed.

Input


Input file contains multiple test cases. In a test case,the first line contains a single positive number N indicating the number of soldiers.(0<=N<=3000) Next N lines :There is only one nonnegative integer on each line , indicating the level number for each soldier.( less than 30 digits);

Output


For each case, output the minimum number of broomsticks on a single line.

Author


PPF@JLU

Solution


無力吐槽配圖

這題的思路還是比較好玩的。顯然只有相同等級的士兵不能互相teach,那么最多的相同數量就是答案了。字典樹

注意0004和4是同一個數字,我們要處理一下前導零 998ms卡過的(汗

Code


#include <iostream>#include <string.h>#include <string>#define rep(i, st, ed) for (int i = st; i <= ed; i += 1)#define fill(x, t) memset(x, t, sizeof(x))#define N 5001#define L 61using namespace std;int map[N][L], p[N], cnt;int ans;inline void insert(int now, string s, int dep){ if (dep == s.length()){ if (++ p[now] > ans){ ans = p[now]; } return; } if (!map[now][s[dep]]){ map[now][s[dep]] = ++ cnt; } insert(map[now][s[dep]], s, dep + 1);}int main(void){ ios::sync_with_stdio(false); int n; while (cin >> n){ ans = 0; cnt = 0; fill(map, 0); fill(p, 0); rep(i, 1, n){ string s; cin >> s; while (s.length() > 1 && s[0] == '0'){ s.erase(0, 1); } insert(0, s, 0); } cout << ans << endl; } return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 灵寿县| 新田县| 商洛市| 儋州市| 无极县| 青河县| 嵊州市| 连云港市| 泗阳县| 和硕县| 叙永县| 兴国县| 容城县| 错那县| 资源县| 固阳县| 湾仔区| 东阿县| 墨玉县| 灵宝市| 兰州市| 芮城县| 威信县| 额济纳旗| 内黄县| 驻马店市| 西丰县| 武义县| 新巴尔虎右旗| 古丈县| 凤凰县| 丰城市| 长沙市| 绍兴县| 寻甸| 黄冈市| 克什克腾旗| 西青区| 正阳县| 堆龙德庆县| 涡阳县|