日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java蛮力法背包问题_蛮力法、动态规划法 求解01背包问题

發布時間:2024/3/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java蛮力法背包问题_蛮力法、动态规划法 求解01背包问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

V(i,j)= (2)

max{V(i-1,j),V(i-1,j-wi)+vi} j>=w

2)復雜度分析:2n

三、程序偽碼:

(1)Brute Force:

Algorithm MFKnapsack(capacity, values, weights, n)

// Input: A nonnegative integer n indicating the number of the frist items being

//considered and a nonnegative integer capacity indicating the knapsack’s capacity, A

array values[] indicating the values of items, A array weights[] indicating the weights

of items.

//Output: The value of an optimal feasible subset of the first i items

if d== c.size()

for (int i = 0; i != d; ++i)

if c[i] == 1

cur_weight += weights[i];

cur_value += values[i];

if cur_weight <= capacity && cur_value > max_value

max_value cur_value;

return;

(2)Dynamic Programming:

總結

以上是生活随笔為你收集整理的java蛮力法背包问题_蛮力法、动态规划法 求解01背包问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。