摘要:偽代碼如下:MaxNutrientValue(n,v,p,M,x)1fori=0ton2nv[i][0]=03forj=1toM4nv[0][j]=05fori=1ton6forj=1toM7ifj<p[i]//若食物mi不能加入到套餐中8nv[i][j]=nv[i-1][j]9elseif(1)10nv[i][j]=nv[i-1][j]11else12nv[i][j]=nv[i-1][j–p[i]]+v[i]13j=M14
偽代碼如下:
MaxNutrientValue(n, v, p, M, x)
1 for i = 0 to n
2 nv[i][0] = 0
3 for j = 1 to M
4 nv[0][j] = 0
5 for i = 1 to n
6 for j = 1 to M
7 if j < p[i] //若食物mi不能加入到套餐中
8 nv[i][j] = nv[i - 1][j]
9 else if (1)
10 nv[i][j] = nv[i - 1][j]
11 else
12 nv[i][j] = nv[i - 1][j – p[i]] + v[i]
13 j = M
14 for i = n downto 1
15 if (2)
16 x[i] = 0
17 else
18 x[i] = 1
19 (3)
20 return x and nv[n][M]
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19]
軟考備考資料免費(fèi)領(lǐng)取
去領(lǐng)取
共收錄117.93萬道題
已有25.02萬小伙伴參與做題