T9 HDU1298
Posted bxd123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了T9 HDU1298相关的知识,希望对你有一定的参考价值。
就是字典树加dfs
把所有操作封在结构体里面
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; const int maxn = 1e5 + 10; char dic[10][8] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}; int n, w, p, m, P; char s[105], num[105], Find[105], ans[105]; struct Trie { int pos; int tree[maxn][26]; int val[maxn]; void clear() { pos = 1; memset(tree[0], 0, sizeof(tree[0])); memset(val, 0, sizeof(val)); } int idx(char c) { return c - ‘a‘; } void insert(char *s, int v) { int root = 0, n = strlen(s); for(int i = 0; i < n; i++) { int ch = idx(s[i]); if(!tree[root][ch]) { memset(tree[pos], 0, sizeof(tree[pos])); tree[root][ch] = pos++; } root = tree[root][ch]; val[root]+=v; } } void query(int cur, int len, int u) { if(cur == len && val[u] > P) { P = val[u]; for(int i = 0; i < len; i++) { Find[i] = ans[i]; Find[len] = ‘