ADS Assignment of DP

Dynamic Programming

  1. Rod-cutting Problem: Given a rod of total length N inches and a table of selling prices P L P_L PL for lengths L=1,2,⋯,M. You are asked to find the maximum revenue R N R_N RN obtainable by cutting up the rod and selling the pieces. For example, based on the following table of prices, if we are to sell an 8-inch rod, the optimal solution is to cut it into two pieces of lengths 2 and 6, which produces revenue R 8 = P 2 + P 6 = 5 + 17 = 22 R_8=P_2+P_6=5+17=22 R8=P2+P6=5+17=22. And if we are to sell a 3-inch rod, the best way is not to cut it at all.
Length L12345678910
Price P L P_L PL1589101717202328

Which one of the following statements is FALSE?

A. This problem can be solved by dynamic programming

B. The time complexity of this algorithm is O ( N 2 ) O(N^2) O(N2)

C. If NM, we have R N = m a x ( P N , m a x 1 ≤ i < N ( R i + R N − i ) ) R_N=max(P_N,max_{1≤i<N}(R_i+R_{N−i})) RN=max(PN,max1i<N(Ri+RNi))

D. If N>M, we have R N = m a x 1 ≤ i < N ( R i + R N − M ) R_N=max_{1≤i<N}(R_i+R_{N−M}) RN=max1i<N(Ri+RNM)

分析:

对于任意一根长度为L的钢管,如果最优解包括一段长度为5的钢管,那么切下5单位长度后的钢管的最优解也是长度为L-5的钢管最优解。

问题的最优解包含相关子问题的最优解,这些子问题我们可以独立求解。

所以我们可以用动态规划的方式写这道题,递推关系式应该是

N > M N\gt M N>M, R N = m a x 1 ≤ i < N ( R i + R N − i ) R_N=max_{1≤i<N}(R_i+R_{N−i}) RN=max1i<N(Ri+RNi)

N ≤ M N\le M NM, R N = m a x ( P N , m a x 1 ≤ i < N ( R i + R N − i ) ) R_N=max(P_N,max_{1≤i<N}(R_i+R_{N−i})) RN=max(PN,max1i<N(Ri+RNi))

问题规模是指数级别的,所以选D.

  1. In dynamic programming, we derive a recurrence relation for the solution to one subproblem in terms of solutions to other subproblems. To turn this relation into a bottom up dynamic programming algorithm, we need an order to fill in the solution cells in a table, such that all needed subproblems are solved before solving a subproblem. Among the following relations, which one is impossible to be computed?

在这里插入图片描述
解题思路
在这里插入图片描述

  1. Given a recurrence equation f i , j , k = f i , j + 1 , k + m i n 0 ≤ l ≤ k ( f i − 1 , j , l + w j , l ) f_{i,j,k}=f_{i,j+1,k}+min_{0≤l≤k}(f_{i−1,j,l}+w_{j,l}){} fi,j,k=fi,j+1,k+min0lk(fi1,j,l+wj,l). To solve this equation in an iterative way, we cannot fill up a table as follows:

此题相当于给定计算顺序,判断是否合理.(答案选B)

在这里插入图片描述

  • 8
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值