画圆的沙滩

亦简亦美

随笔分类 -  编程之美

上一页 1 2

讨论讨论《编程之美》。
编辑距离
摘要:好吧。我还没习惯Live Writer。这部分被覆盖掉了。贴回来。编辑距离,编程之美3.3节。这个问题类似于最长公共子序列LCS,所以可以使用DP和滚动数组来简化计算。int editdist(const string& w1, const string& w2) { size_t len1 = w1.length(), len2 = w2.length(); if (len1++ < len2++) return editdist(w2, w1); int* dist = new int[len2]; for (size_t j = 0; j < len2; ++ 阅读全文

posted @ 2011-03-11 16:33 acmaru 阅读(179) 评论(0) 推荐(0)

24点
摘要:随便写点24点游戏求解程序。两种解法。通过Live Writer 投递,再次测试。编程之美1.16节。关于最后一个扩展问题:引入阶乘运算。对于DP实现,这个不会成为问题。但是,对于深搜,由于阶乘运算不会减少集合的基数,需要进行减枝。其中的一种策略是,当集合中最大的数字除去所有余下的数仍然大于24的话,就可以不必继续了。公共代码:struct Expr { double r; string e; Expr(double rr = 0, const string& ee = ""): r(rr), e(ee) {} bool operator<(const Exp 阅读全文

posted @ 2011-03-11 16:10 acmaru 阅读(304) 评论(0) 推荐(0)

上一页 1 2

导航