分析:
题意很好懂,将一列数划分为尽可能少的有序数列。
这其中有一个简单难得的性质:相同的数的个数决定了划分的数列个数。
如果题目数据小的话,可以直接统计。但是本题有提示数据位数直逼30位,而且有前导0,故考虑字符串哈希统计个数。
代码:
(参考了书上的,毕竟刚学,先掌握一下姿势。)
#include <cstdio>
#include <cstring>
#include <cstdlib>
const int maxn = 7010;
char s[32];
int hash[maxn], count[maxn];
int n;
int ans;
inline int ELFHash(char *key) {
unsigned long h = 0;
while (*key) {
h = (h << 4) + (*key++);
unsigned long g = h & 0xf0000000L;
if (g)
h ^= g >> 24;
h &= ~g;
}
return h;
}
inline void hashit(char *s) {
int k;
while (*s == '0') s++;
k = ELFHash(s);
int t = k % maxn;
while (hash[t] != k && hash[t] != -1) {
t = (t + 10) % maxn;
}
if (hash[t] == -1) {
count[t] = 1;
hash[t] = k;
}
else if (++count[t] > ans)
ans = count[t];
return;
}
int main() {
#ifndef LOC
freopen("in.txt", "r", stdin);
#endif
while (~scanf("%d", &n)) {
memset(hash, -1, sizeof(hash));
getchar();
ans = 1;
for (int i = 0; i < n; i++) {
scanf("%s", s);
hashit(s);
}
printf("%d\n", ans);
}
return 0;
}