摘要: Trie水题,将每个单词插入Trie树,然后暴力拆分每个单词到树中查找匹配即可!有几个要注意的细节,代码注释中都标上了。My Code:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int MAX = 50007;struct node{ int flag; node * next[26];};char dis[MAX][30];node * newnode(){ int i; node * p = new node; p->flag = 阅读全文
posted @ 2011-08-21 21:12 AC_Von 阅读(296) 评论(0) 推荐(0) 编辑
摘要: 题意:这题很好理解,给一个字典,上边有火星文对应的英语,让后输入一句话,把它翻译成英语。 思路:定义Tire树时加一个存放字符串的数组s[],按字典上的火星文建立Trie树,在每一个火星文的末尾将对应的英文存到s[]中。查找时如果能在Trie树中找到,就将s[]对应的串取出来(至于怎么取,自己先想想。。。)分解输入的句子时注意细节。还有就是静态建立Trie树,我开始用动态,WA了。。。My Code:#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>us 阅读全文
posted @ 2011-08-21 19:05 AC_Von 阅读(529) 评论(0) 推荐(0) 编辑
摘要: 要输出最长上升子序列,只需加一个pre数组,记录新加如序列的前一个。最后遍历一遍数组就可以。代码如下:#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 1000;int num[N];int pre[N];int dp[N];int f[N];int main(){ freopen("data.in", "r", stdin); int n, i, j, ans, flag; while(~sc 阅读全文
posted @ 2011-08-21 09:34 AC_Von 阅读(1432) 评论(0) 推荐(0) 编辑