{"id":15460,"date":"2009-07-14T18:06:21","date_gmt":"2009-07-14T10:06:21","guid":{"rendered":"http:\/\/kaiyan.yo2.cn\/?p=15460"},"modified":"2009-07-14T18:06:21","modified_gmt":"2009-07-14T10:06:21","slug":"01%e8%83%8c%e5%8c%85%e5%92%8c%e5%ae%8c%e5%85%a8%e8%83%8c%e5%8c%85%e7%9a%84java%e8%a7%a3%e6%b3%95","status":"publish","type":"post","link":"http:\/\/yankay.com\/01%e8%83%8c%e5%8c%85%e5%92%8c%e5%ae%8c%e5%85%a8%e8%83%8c%e5%8c%85%e7%9a%84java%e8%a7%a3%e6%b3%95\/","title":{"rendered":"0\/1\u80cc\u5305\u548c\u5b8c\u5168\u80cc\u5305\u7684java\u89e3\u6cd5"},"content":{"rendered":"
\u80cc\u5305\u95ee\u9898\uff1a<\/p>\n
\u73b0\u6709 n \u4ef6\u7269\u54c1\uff0c\u4e00\u4e2a\u6700\u5927\u5bb9\u91cf\u4e3a maxWeight \u7684\u80cc\u5305\u3002\u7b2c i \u4ef6\u7269\u54c1\u91cd\u91cf\u4e3a weights[i] \uff0c\u4ef7\u503c\u4e3a values[i] \u3002\u5982\u679c\u662f0\/1\u80cc\u5305\uff0c\u5bf9\u4e8e\u4e00\u4ef6\u7269\u54c1\uff0c\u4f60\u5fc5\u987b\u9009\u62e9\u53d6\u6216\u4e0d\u53d6\uff0c\u4e14\u6bcf\u4ef6\u7269\u54c1\u53ea\u80fd\u88ab\u53d6\u4e00\u6b21\uff08\u8fd9\u5c31\u662f\u201c0\/1\u201d\u7684\u542b\u4e49\uff09\uff1b\u5982\u679c\u662f\u5b8c\u5168\u80cc\u5305\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u4efb\u610f\u591a\u4ef6\u3002<\/p>\n
\u6c42\u653e\u7f6e\u54ea\u51e0\u4ef6\u7269\u54c1\u8fdb\u80cc\u5305\uff0c\u4f7f\u5f97\u80cc\u5305\u4e2d\u7269\u54c1\u4ef7\u503c\u6700\u5927\u3002<\/p>\n
\u601d\u8def\uff1a\u63a8\u8350<\/p>\n
\u8bf4\u7684\u6e05\u6e05\u695a\u695a\u5730\u3002<\/p>\n
\u4ee3\u7801\u6700\u5b9e\u9645\u4e86\uff1a
\n0\/1\u80cc\u5305<\/p>\n
\npublic static int unpack(int[] values, int[] weights, int maxWeight) {\n int[] ans = new int[maxWeight + 1];\n for (int i = 0; i < values.length; i++) {\n for (int j = maxWeight; j >= weights[i]; j--) {\n int takeValue = values[i] + ans[j - weights[i]];\n if (takeValue > ans[j]) {\n ans[j] = takeValue;\n }\n }\n }\n return ans[ans.length - 1];\n}<\/pre>\n\u5b8c\u5168\u80cc\u5305\uff1a<\/p>\n
\npublic static int unpack(int[] values, int[] weights, int maxWeight) {\n int[] ans = new int[maxWeight + 1];\n for (int i = 0; i < values.length; i++) {\n for (int j = weights[i]; j <= maxWeight; j++) {\n int takeValue = values[i] + ans[j - weights[i]];\n if (takeValue > ans[j]) {\n ans[j] = takeValue;\n }\n }\n }\n return ans[maxWeight];\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"\u80cc\u5305\u95ee\u9898\uff1a \u73b0\u6709 n \u4ef6\u7269\u54c1\uff0c\u4e00\u4e2a\u6700\u5927\u5bb9\u91cf\u4e3a maxWeight \u7684\u80cc\u5305\u3002\u7b2c i \u4ef6\u7269\u54c1\u91cd\u91cf\u4e3a weights […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"yoast_head":"\n
0\/1\u80cc\u5305\u548c\u5b8c\u5168\u80cc\u5305\u7684java\u89e3\u6cd5 - \u6211\u81ea\u7136<\/title>\n\n\n\n\n\n\n\n\n\n\n