跳到主要内容

東京大学 情報理工学系研究科 創造情報学専攻 2021年8月実施 筆記試験 第1問

Author​

itsuitsuki, 祭音Myyura

Description​

Let nn and rr be positive integers. For i=1,2,…,ni=1,2,\dots,n, let fif_i be a univariate real-valued function defined in the integer domain and let fi(xi)f_i(x_i) be −∞-\infty for negative integer xix_i. Any non-negative integer solution (x1,…,xn)(x_1,\dots,x_n) that satisfies ∑i=1nxi=r\sum_{i=1}^n x_i=r is called a feasible solution. In addition, a feasible solution that maximizes the objective function ∑i=1nfi(xi)\sum_{i=1}^n f_i(x_i) is called an optimal solution and the objective function value at the solution is called the optimal value. This problem is expressed as follows.

(P) ∣ Maximize∑i=1nfi(xi)subject to∑i=1nxi=rxi is a non-negative integer, i=1,…,n(P) \ \left| \ \begin{aligned} &\text{Maximize} && \sum_{i=1}^n f_i(x_i) \\ &\text{subject to} && \sum_{i=1}^n x_i=r \\ &&& x_i \text{ is a non-negative integer, } i=1,\dots,n \end{aligned} \right.

(1)​

For i=1,2,…,ni=1,2,\dots,n and non-negative integer α\alpha, define the function di(α):=fi(α)−fi(α−1)d_i(\alpha):=f_i(\alpha)-f_i(\alpha-1) and assume that di(α)d_i(\alpha) is non-increasing in terms of α\alpha. Apply the following greedy algorithm AG\mathcal{A}_G to (P)(P).

Step 0: For i=1,2,…,ni=1,2,\dots,n, set xi←0x_i\leftarrow 0.

Step 1: Repeat the following procedure for rr times: Let γ\gamma be any index ii that maximizes di(xi+1)d_i(x_i+1) among i=1,2,…,ni=1,2,\dots,n, and set xγ←xγ+1x_{\gamma}\leftarrow x_{\gamma}+1.

Answer the following questions.

(1-1) Let r=5,n=3r=5,n=3, and let f1,f2,f3f_1,f_2,f_3 take the following values. Notice that d1,d2,d3d_1,d_2,d_3 are non-increasing. Answer the solution obtained by the greedy algorithm AG\mathcal{A}_G.

α\alpha0123…\dots
f1(α)f_1(\alpha)00-8-24…\dots
f2(α)f_2(\alpha)-21-14-40…\dots
f3(α)f_3(\alpha)0-3-12-22…\dots

(1-2) Let (x1∗,x2∗,…,xn∗)(x_1^*,x_2^*,\dots,x_n^*) be a feasible solution. Show that it is an optimal solution of (P)(P) if and only if the following condition holds.

max⁡i=1,2,…,ndi(xi∗+1)≤min⁡i=1,2,…,ndi(xi∗)\max_{i=1,2,\dots,n}d_i(x_i^*+1)\le\min_{i=1,2,\dots,n}d_i(x_i^*)

(1-3) Show that the greedy algorithm AG\mathcal{A}_G outputs an optimal solution of (P)(P).

(2)​

Unless the non-increasing assumption of (1) holds, the greedy algorithm AG\mathcal{A}_G does not always output an optimal solution of (P)(P). To apply dynamic programming, we consider the following problem (PNR)(P_N^R) in which nn and rr in (P)(P) are replaced with N∈{1,2,…,n}N\in\{1,2,\dots,n\} and R∈{0,1,…,r}R\in\{0,1,\dots,r\}, respectively.

(PNR) ∣ Maximize∑i=1Nfi(xi)subject to∑i=1Nxi=Rxi is a non-negative integer, i=1,…,N(P_N^R) \ \left| \ \begin{aligned} &\text{Maximize} && \sum_{i=1}^N f_i(x_i) \\ &\text{subject to} && \sum_{i=1}^N x_i = R \\ &&& x_i \text{ is a non-negative integer, } i = 1, \dots, N \end{aligned} \right.

The optimal value of the problem is denoted by gN(R)g_N(R). Answer the following questions.

(2-1) Express gN(R)g_N(R) only with gN−1(c)g_{N-1}(c) and fN(c)f_N(c) for any non-negative integer cc in the case of N≥2N\ge 2.

(2-2) Write a pseudo-code of a dynamic programming algorithm within 15 lines to output the optimal value gn(r)g_n(r) of (P)(P). Hereafter, this algorithm is called AD\mathcal{A}_D.

(2-3) Show that the optimal value of (P)(P) is obtained by the dynamic programming algorithm AD\mathcal{A}_D.

(2-4) Answer the computational complexity of the dynamic programming algorithm AD\mathcal{A}_D and the computational complexity of the greedy algorithm AG\mathcal{A}_G. Ignore the computational cost of calculating f1,…,fnf_1,\dots,f_n.

题目描述​

给定正整数 n,rn,r。对 i=1,…,ni=1,\ldots,n,fif_i 是定义在整数域上的一元实值函数,并约定负整数 xix_i 时 fi(xi)=−∞f_i(x_i)=-\infty。满足 xix_i 为非负整数且 ∑i=1nxi=r\sum_{i=1}^nx_i=r 的解为可行解;使 ∑ifi(xi)\sum_i f_i(x_i) 最大者为最优解,其目标值为最优值:

(P)最大化∑i=1nfi(xi)约束∑i=1nxi=r,xi∈Z≥0.(P)\quad \begin{array}{ll} \text{最大化}&\displaystyle\sum_{i=1}^nf_i(x_i)\\ \text{约束}&\displaystyle\sum_{i=1}^nx_i=r,\quad x_i\in\mathbb Z_{\ge0}. \end{array}

1. 边际收益非增时的贪心算法

定义

di(α)=fi(α)−fi(α−1)d_i(\alpha)=f_i(\alpha)-f_i(\alpha-1)

并假设对非负整数 α\alpha,每个 di(α)d_i(\alpha) 随 α\alpha 非增。算法 AG\mathcal A_G:

  • 初始令所有 xi=0x_i=0。
  • 重复 rr 次:任选使 di(xi+1)d_i(x_i+1) 最大的下标 γ\gamma,令 xγ←xγ+1x_\gamma\leftarrow x_\gamma+1。
  1. 当 r=5,n=3r=5,n=3 且函数值如下时,求 AG\mathcal A_G 输出的解:

    α\alpha0123…\dots
    f1(α)f_1(\alpha)00-8-24…\dots
    f2(α)f_2(\alpha)-21-14-40…\dots
    f3(α)f_3(\alpha)0-3-12-22…\dots
  2. 对任一可行解 (x1∗,…,xn∗)(x_1^*,\ldots,x_n^*),证明它最优当且仅当

    max⁡idi(xi∗+1)≤min⁡idi(xi∗).\max_i d_i(x_i^*+1)\le\min_i d_i(x_i^*).
  3. 证明贪心算法 AG\mathcal A_G 必输出最优解。

2. 一般情形的动态规划

若边际收益非增假设不成立,贪心不一定最优。把 PP 中 n,rn,r 分别替换为 N∈{1,…,n}N\in\{1,\ldots,n\}、R∈{0,…,r}R\in\{0,\ldots,r\},定义子问题

(PNR)最大化∑i=1Nfi(xi)约束∑i=1Nxi=R,xi∈Z≥0,(P_N^R)\quad \begin{array}{ll} \text{最大化}&\displaystyle\sum_{i=1}^Nf_i(x_i)\\ \text{约束}&\displaystyle\sum_{i=1}^Nx_i=R,\quad x_i\in\mathbb Z_{\ge0}, \end{array}

其最优值记为 gN(R)g_N(R)。

  1. 当 N≥2N\ge2 时,只使用非负整数 cc 对应的 gN−1(c)g_{N-1}(c) 与 fN(c)f_N(c) 写出 gN(R)g_N(R) 的递推式。
  2. 用不超过 15 行伪代码写动态规划算法 AD\mathcal A_D,输出 gn(r)g_n(r)。
  3. 证明 AD\mathcal A_D 得到 PP 的最优值。
  4. 分别给出 AD\mathcal A_D 与 AG\mathcal A_G 的计算复杂度,忽略计算各 fif_i 的代价。

Kai​

(1)​

(1-1)​

The selected indices are 2,1,3,1,32,1,3,1,3. Therefore

(x1,x2,x3)=(2,1,2).\boxed{(x_1,x_2,x_3)=(2,1,2)}.

(1-2)​

Set di(0)=+∞d_i(0)=+\infty, as follows from fi(−1)=−∞f_i(-1)=-\infty.

If the condition fails, choose p,qp,q such that dp(xp∗+1)>dq(xq∗)d_p(x_p^*+1)>d_q(x_q^*). Necessarily xq∗>0x_q^*>0. Moving one unit from qq to pp changes the objective by

dp(xp∗+1)−dq(xq∗)>0,d_p(x_p^*+1)-d_q(x_q^*)>0,

so x∗x^* is not optimal.

Conversely, compare x∗x^* with any feasible xx. Every marginal added where xi>xi∗x_i>x_i^* is at most max⁡idi(xi∗+1)\max_i d_i(x_i^*+1), while every marginal removed where xi<xi∗x_i<x_i^* is at least min⁡idi(xi∗)\min_i d_i(x_i^*). The numbers added and removed are equal. Under the stated inequality, the objective at xx cannot exceed that at x∗x^*; hence x∗x^* is optimal.

(1-3)​

Fix jj with final xj>0x_j>0 and consider the last iteration that increments xjx_j. Greedy selection gives, for every ii, the selected marginal dj(xj)d_j(x_j) at least the then-available marginal of ii. Since each did_i is non-increasing, the final value satisfies

di(xi+1)≤dj(xj).d_i(x_i+1)\le d_j(x_j).

For xj=0x_j=0, dj(0)=+∞d_j(0)=+\infty. Thus the condition in (1-2) holds, so the greedy output is optimal.

(2)​

(2-1)​

Assigning cc units to the last variable leaves R−cR-c units for the first N−1N-1 variables:

gN(R)=max⁡0≤c≤R{gN−1(R−c)+fN(c)},g1(R)=f1(R).\boxed{g_N(R)=\max_{0\le c\le R}\{g_{N-1}(R-c)+f_N(c)\}}, \qquad g_1(R)=f_1(R).

(2-2)​

for R = 0 to r:
g[1,R] = f_1(R)
for N = 2 to n:
for R = 0 to r:
g[N,R] = -infinity
for c = 0 to R:
g[N,R] = max(g[N,R],
g[N-1,R-c] + f_N(c))
return g[n,r]

(2-3)​

The base row is the exact optimum for one variable. Assuming row N−1N-1 is optimal, every feasible solution for (PNR)(P_N^R) has one value xN=cx_N=c and an optimal value at most gN−1(R−c)+fN(c)g_{N-1}(R-c)+f_N(c). Conversely, combining the maximizing cc with an optimizer of that subproblem is feasible. Induction proves that the algorithm returns gn(r)g_n(r).

(2-4)​

The dynamic program takes Θ(r+(n−1)r2)\Theta(r+(n-1)r^2) time, or Θ(nr2)\Theta(nr^2) for n≥2n\ge2, and Θ(nr)\Theta(nr) space, reducible to Θ(r)\Theta(r) space with two rows. A direct implementation of the stated greedy algorithm scans nn marginals in each of rr iterations, taking Θ(nr)\Theta(nr) time and Θ(n)\Theta(n) space.