Showing posts with label IT/Algorithm. Show all posts
Showing posts with label IT/Algorithm. Show all posts

Tuesday, July 24, 2007

适用动态编程的两个条件

1。最优子结构
2。重叠子问题
昨天马云说,最简单的事情最难做好。我想把最简单的事情做好先。

证明-矩阵最小乘数问题





show that the solution to the recurrence is Ω(2n).
这个问题是这样的:
Ω(2n) 即只要 >= 2n
第一步,n=1,有p(1) = 1 =
20
第二步,n <>Ω(2n) >= 2n
第三步,n= l ,p(n) = sigma: p(k)p(n - k)。因为k & n-k 小于l,于是有
p(n) >=
2k * 2n-k= 2n

符号所代表的意义相当的重要,没有Ω(2n)>=2n的解释,基本很难证明这个命题。

Monday, July 23, 2007

今天最后一个

There might exist some ei, ai,j, and ti,j values for which FASTEST-WAY produces li[j] values such that l1[j] = 2 and l2[j] = 1 for some station number j. Assuming that all transfer costs ti,j are nonnegative.

证明:
l1[j] = 2 说明 f1[j] = f2[j-1] + a1[j] + t2[j-1] 说明 f2[j-1] + a1[j] + t2[j-1] < f1[j-1] + a1[j],说明f2[j-1] + t2[j-1] < f1[j-1] ,(1)
l2[j] = 1 说明 f2[j] = f1[j-1] + a2[j] + t1[j-1] 说明 f1[j-1] + a2[j] + t1[j-1] < f2[j-1] + a2[j],说明
f1[j-1] + t1[j-1] < f2[j-1], (2)
(1) + (2) 得到:t2[j-1] + t1[j-1] < 0
但是ti,j are nonnegative,所以产生了矛盾.命题错误.

这个命题说明了什么?为什么反过来不正确呢?难道不应该是对称的吗?
以上是纯形式化的证明,由于没有用我的实际经验进行验证,所以让我觉得心中没有底.

再请证明

∑2i=1∑nj=1 ri(j) is exactly 2n+1 - 2

证明如下:
∑2i=1∑nj=1 ri(j) = ∑2i=1∑nj=1 2n-j = ∑2i=1(20 + ... + 2n-1) = (21 + ... + 2n) = 2n+1 - 2

请证明

r1(n) = r2(n) = 1

r1(j) = r2(j) = r1(j+1) + r2(j+1)

Use above equations to show that ri(j), the number of references made to fi[j] in a recursive algorithm, equals 2n - j.


证明如下:

第一步:n - j = 1
r1(j)=r2(j) = r1(j+1) + r2(j+1) = r1(n) + r2(n) = 2 = 2n - j

第二步:若n - j = k
r1(j)=r2(j) = r1(j+1) + r2(j+1) = 2n - j

若当n - j = k + 1
r1(j) = r1(j+1) + r2(j+1)
因为 n - (j+1) = k,所以 r1(j) = 2n - (j +1) + 2n - (j +1) = 2n - j

综上,命题得证。
纪念,走出数学系后的第五个年头的一个归纳法证明。


Tuesday, July 17, 2007

Dynamic programming - Pattern to find optimal substructure

1. Solution to the problem consists of making a choice.
2. Suppose for a given problem, a choice is given to lead to an optimal solution.
3. Given this choice, determine which subproblems ensue and how to best characterize the resulting space of subproblems.
4. Show solution to subproblem must be optimal by using "cut-and-paste" technique.