2012年8月5日

[状态压缩DP] PKU 3311 Hie with the Pie

摘要: 和COJ送货到家一样,不过这里不要求每个点只经过一次,因此可以先用floyd预处理出任意两点间的最短距离,然后状态压缩DP。# include <cstdio># include <cstring># define INF 0x3C3C3C3C# define N 10 + 2int n;int w[N][N];int f[1<<N][N];int Min(int x, int y){ return x<y ? x:y;}int dp(int s, int i){ int &ans = f[s][i]; if (ans != -1) retur 阅读全文

posted @ 2012-08-05 22:54 getgoing 阅读(226) 评论(0) 推荐(0) 编辑

[简单DP] HDOJ 4323 Magic Number

摘要: // 编辑距离的方法可以水过这道题编辑距离的计算方法即一个不完全的证明见:http://en.wikipedia.org/wiki/Levenshtein_distance具体如下图:# include <cstdio># include <cstring># define LEN 10 + 2# define N 1500 + 5int n, m;char s[LEN];int len[N];char dic[N][LEN];int Abs(int x){ return x>0 ? x:-x;}int Min(int x, int y, int z){ int 阅读全文

posted @ 2012-08-05 22:12 getgoing 阅读(235) 评论(0) 推荐(0) 编辑

[字典树入门] HDOJ 1251 统计难题

摘要: 不需要保存是否结束(isend),在插入时每经过一个节点,将该节点的计数器 +1,在查找时输出最后一个字符所在节点的cnt值即可;PS:为什么加了删除树(del_Trie)会超时呢?# include <cstdio># include <cstring># define LEN 10 + 1struct node{ int cnt; node * next[26]; node () { cnt = 0; memset(next, 0, sizeof(next)); }};void insert_Trie(node *root, cha... 阅读全文

posted @ 2012-08-05 19:01 getgoing 阅读(213) 评论(0) 推荐(0) 编辑

[状态压缩DP] PKU 2411 Mondriaan's Dream

摘要: 参考http://wenku.baidu.com/view/e262a86f1eb91a37f1115c26.html状态设计:0表示横放,1表示竖放,可以预处理出所有合法状态,f[i, s] 表示到达第 i 层的状态(类似俄罗斯方块,前 i 层合并之后剩余的状态)。状态转移:f[i, s] = sum{f[i-1, s']},s' 为和 s 符合的状态 j 与 s 的异或值。# include <cstdio># include <cstring># define N 11 + 1typedef long long int LL;int m, n;LL 阅读全文

posted @ 2012-08-05 17:25 getgoing 阅读(239) 评论(0) 推荐(0) 编辑

[状态压缩DP] COJ 1129 送货到家

摘要: 第一道状态压缩DP;这道题要求一个无向图的最小权回路,要求经过所有点,所以可以任选一个点(这里选0)作为起点,以后的状态f[s, i]表示从0出发到i结束的最小权路径,最终求得f[1<<n-1, k]后要加上w[0, k],然后求最小值:for k = 0:n-1 ans = min(f[1<<n-1, k]+w[0, k]);print(ans); 1 # include <cstdio> 2 # include <cstring> 3 4 # define N 15 5 # define INF 0X1FFFFFFF 6 7 int n; 8 阅读全文

posted @ 2012-08-05 09:21 getgoing 阅读(163) 评论(0) 推荐(0) 编辑

USACO Section 1.3 Calf Flac

摘要: manacher求最长子串。/*PROG : calfflacLANG : C++*/# include <cstdio># include <cctype># define N 20000 + 5int n;char s[N];int Min(int x, int y){ return x < y ? x : y;}int manacher(char *s, int len, int &st){ int n = len*2+1; char t[2 * N]; /* insert '#' in string s to form a 2*le 阅读全文

posted @ 2012-08-05 08:25 getgoing 阅读(217) 评论(0) 推荐(0) 编辑

导航