\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<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/yankay.com\/01\u80cc\u5305\u548c\u5b8c\u5168\u80cc\u5305\u7684java\u89e3\u6cd5\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"0\/1\u80cc\u5305\u548c\u5b8c\u5168\u80cc\u5305\u7684java\u89e3\u6cd5 - \u6211\u81ea\u7136\" \/>\n<meta property=\"og:description\" content=\"\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 […]\" \/>\n<meta property=\"og:url\" content=\"http:\/\/yankay.com\/01\u80cc\u5305\u548c\u5b8c\u5168\u80cc\u5305\u7684java\u89e3\u6cd5\/\" \/>\n<meta property=\"og:site_name\" content=\"\u6211\u81ea\u7136\" \/>\n<meta property=\"article:published_time\" content=\"2009-07-14T10:06:21+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"http:\/\/yankay.com\/#website\",\"url\":\"http:\/\/yankay.com\/\",\"name\":\"\\u6211\\u81ea\\u7136\",\"description\":\"\\u989c\\u5f00\\u7684\\u535a\\u5ba2\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"http:\/\/yankay.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-CN\"},{\"@type\":\"WebPage\",\"@id\":\"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\/#webpage\",\"url\":\"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\/\",\"name\":\"0\/1\\u80cc\\u5305\\u548c\\u5b8c\\u5168\\u80cc\\u5305\\u7684java\\u89e3\\u6cd5 - \\u6211\\u81ea\\u7136\",\"isPartOf\":{\"@id\":\"http:\/\/yankay.com\/#website\"},\"datePublished\":\"2009-07-14T10:06:21+00:00\",\"dateModified\":\"2009-07-14T10:06:21+00:00\",\"author\":{\"@id\":\"http:\/\/yankay.com\/#\/schema\/person\/f52d918e9bfa51c4454172c2caa7704f\"},\"breadcrumb\":{\"@id\":\"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\/#breadcrumb\"},\"inLanguage\":\"zh-CN\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"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\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"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\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"http:\/\/yankay.com\/\",\"url\":\"http:\/\/yankay.com\/\",\"name\":\"\\u9996\\u9875\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"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\/#webpage\"}}]},{\"@type\":\"Person\",\"@id\":\"http:\/\/yankay.com\/#\/schema\/person\/f52d918e9bfa51c4454172c2caa7704f\",\"name\":\"yankay\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"http:\/\/yankay.com\/#personlogo\",\"inLanguage\":\"zh-CN\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/426bb830224c1471011d92a830a6ed4f?s=96&d=wavatar&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/426bb830224c1471011d92a830a6ed4f?s=96&d=wavatar&r=g\",\"caption\":\"yankay\"},\"sameAs\":[\"http:\/\/47.100.65.109\"],\"url\":\"http:\/\/yankay.com\/author\/yankay\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/posts\/15460"}],"collection":[{"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/comments?post=15460"}],"version-history":[{"count":0,"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/posts\/15460\/revisions"}],"wp:attachment":[{"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/media?parent=15460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/categories?post=15460"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yankay.com\/wp-json\/wp\/v2\/tags?post=15460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}