{"id":62,"date":"2011-10-30T02:23:31","date_gmt":"2011-10-29T18:23:31","guid":{"rendered":"http:\/\/rexdf.website.org\/?p=4"},"modified":"2011-10-30T02:23:31","modified_gmt":"2011-10-29T18:23:31","slug":"poj1014-%e5%a4%9a%e9%87%8d%e8%83%8c%e5%8c%85-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%bc%98%e5%8c%96-%e5%8f%96%e6%a8%a1%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/blog.rexdf.org\/ja\/2011\/10\/poj1014-%e5%a4%9a%e9%87%8d%e8%83%8c%e5%8c%85-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%bc%98%e5%8c%96-%e5%8f%96%e6%a8%a1%e4%bc%98%e5%8c%96\/","title":{"rendered":"POJ1014: \u591a\u91cd\u80cc\u5305 + \u4e8c\u8fdb\u5236\u4f18\u5316 + \u53d6\u6a21\u4f18\u5316"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u95ee\u9898\u63cf\u8ff0\uff1a<\/p>\n<p>\u6709\u82e5\u5e72\u4ef7\u503c\u4e3a\u5206\u522b\u4e3a1\uff0c2 \uff0c3\uff0c4\uff0c5\uff0c6\u7684\u5927\u7406\u77f3\uff0c\u6c42\u603b\u4ef7\u503c\u7684\u5747\u5206\u7b56\u7565\u3002\u8bbe\u4ef7\u503c\u4e3aV\u7684\u77f3\u5934\u91cd\u91cf\u4e3aV,\u8fd9\u6279\u77f3\u5934\u7684\u603b\u4ef7\u503c\u4e3aSUM,\u5219\u95ee\u9898\u8f6c\u5316\u4e3a\u9009\u53d6\u82e5\u5e72\u5927\u7406\u77f3\u5c06\u5bb9\u91cf\u4e3aSUM\/2\u7684\u80cc\u5305\u88c5\u6ee1\u3002<\/p>\n<p>\u80cc\u5305\u95ee\u9898\uff08\u53c2\u8003\u201c\u80cc\u5305\u95ee\u98989\u8bb2\u201d\uff09<\/p>\n<p>\u6709N\u4ef6\u7269\u54c1\u548c\u4e00\u4e2a\u5bb9\u91cf\u4e3aV\u7684\u80cc\u5305\uff0c\u7b2ci\u4ef6\u7269\u54c1\u7684\u8d39\u7528\u662fc[i]\uff0c\u4ef7\u503c\u662fw[i]\u3002 f[i][v]\u8868\u793a\u524di\u4ef6\u7269\u54c1\u6070\u653e\u5165\u4e00\u4e2a\u5bb9\u91cf\u4e3av\u7684\u80cc\u5305\u53ef\u4ee5\u83b7\u5f97\u7684\u6700\u5927\u4ef7\u503c,\u5219\u6709\uff1a<\/p>\n<p>0-1\u80cc\u5305<\/p>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b<\/td>\n<td>f[i][v] = max{f[i-1][v], f[i-1][v-c[i]]+w[i]}<\/td>\n<\/tr>\n<tr>\n<td>\u89e3\u6cd5 O(VN)<\/td>\n<td>for i = 1\u2026N<\/p>\n<p>for v = V\u2026c[i]<\/p>\n<p>f[v] = max{f[v], f[v-c[i]]+w[i]};<\/td>\n<\/tr>\n<tr>\n<td>\u5b50\u8fc7\u7a0b<\/td>\n<td>procedure ZeroOnePack(cost, weight)<\/p>\n<p>for v = V\u2026cost<\/p>\n<p>f[v] = max{f[v], f[v-cost]+weight}<\/td>\n<\/tr>\n<tr>\n<td>\u521d\u59cb\u5316<\/td>\n<td>\u8981\u6c42\u6070\u597d\u88c5\u6ee1\u80cc\u5305\uff1a f[0] = 0, f[1\u2026V] = \u20131<\/p>\n<p>\u53ea\u8981\u6c42\u4ef7\u503c\u6700\u5927: f[0\u2026V] = 0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u5b8c\u5168\u80cc\u5305<\/p>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b O(V*\u03a3(V\/c[i]))<\/td>\n<td>f[i][v] = max{f[i-1][v-k*c[i]]+k*w[i]|0&lt;=k*c[i]&lt;=v}<\/td>\n<\/tr>\n<tr>\n<td>\u8f6c\u5316\u4e3a0-1\u80cc\u5305\u95ee\u9898 O(VN)<\/td>\n<td>for i = 1\u2026N<\/p>\n<p>for v = cost\u2026V<\/p>\n<p>f[v] = max{f[v], f[v-cost]+weight}<\/td>\n<\/tr>\n<tr>\n<td>\u5b50\u8fc7\u7a0b<\/td>\n<td>procedure CompletePack(cost, weight)<\/p>\n<p>for v = cost\u2026V<\/p>\n<p>f[v] = max{f[v], f[v-cost]+weight}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u591a\u91cd\u80cc\u5305 (\u6307\u5b9a\u6bcf\u4ef6\u7269\u54c1\u7684\u4e2a\u6570n[i])<\/p>\n<div>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b O(V*\u03a3n[i])<\/td>\n<td>f[i][v] = max{f[i-1][v-k*c[i]]+k*w[i]|0&lt;=k&lt;=n[i]}<\/td>\n<\/tr>\n<tr>\n<td>\u4e8c\u8fdb\u5236\u4f18\u5316 O(V*\u03a3log(n[i]))<\/td>\n<td>\u5c06\u7b2ci\u79cd\u7269\u54c1\u4ee52\u7684\u6307\u6570\u5206\u5806\uff1a1\uff0c2\uff0c4\uff0c\u2026\uff0c2^(k-1)\uff0cn[i]-2^k+1,\u4e14<\/p>\n<p>k\u662f\u6ee1\u8db3n[i]-2^k+1&gt;0\u7684\u6700\u5927\u6574\u6570\u3002\u6bcf\u6b21\u5904\u7406\u4e00\u5806\u800c\u4e0d\u662f\u4e00\u4e2a\u7269\u54c1\u3002<\/td>\n<\/tr>\n<tr>\n<td>\u4f2a\u4ee3\u7801<\/td>\n<td>procedure MultiplePack(cost, weight, amount)<\/p>\n<p>if cost*amount&gt;=V<\/p>\n<p>CompletePack(cost, weight)<\/p>\n<p>return<\/p>\n<p>integer k=1<\/p>\n<p>while k&lt;amount<\/p>\n<p>ZeroOnePack(k*cost, k*weight)<\/p>\n<p>amount = amount \u2013 k<\/p>\n<p>k = k * 2<\/p>\n<p>ZeroOnePack(amount*cost, amount*weight)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u53d6\u6a21\u4f18\u5316<\/p>\n<p>\u5f53\u8f93\u5165\u6837\u672c\u7279\u522b\u5927\u65f6\uff0c\u6bd4\u5982\u7ed9\u51fa\u4e0a\u767e\u4e07\u4ef6\u7269\u54c1\uff0c\u8fd9\u65f6\u5019\u4ec5\u9760\u4f18\u5316\u7b97\u6cd5\u4ecd\u7136\u4e0d\u80fd\u4f7f\u8fd0\u884c\u65f6\u95f4\u964d\u5230\u6ee1\u610f\u7684\u8303\u56f4\u3002\u53ef\u8003\u8651\u5982\u4f55\u51cf\u5c11\u8f93\u5165\u6837\u672c\u3002poj1014\u7684discussion\u4e0a\u6709\u4e00\u4e2a\u975e\u5e38\u5de7\u5999\u7684\u201c\u53d6\u6a21\u4f18\u5316\u201d\u6cd5\u3002<\/p>\n<p>\u8bbe\u4ef7\u503c\u4e3av(1&lt;=v&lt;=6)\u7684\u7269\u54c1\u5171\u6709n\u4ef6\uff0c\u6211\u4eec\u5e0c\u671b\u627e\u5230\u4e00\u4e2a\u6bd4\u8f83\u5c0f\u7684\u6570s(s&lt;n), \u4e14\u5c06n\u4ef6\u7269\u54c1v\u51cf\u5c11\u5230s\u6216s-1\u4ef6\uff0c\u95ee\u9898\u7684\u53ef\u5206\u6027\u4e0d\u53d8\u3002\u8003\u8651\u4e0d\u53ef\u5206\u548c\u53ef\u5206\u4e24\u79cd\u60c5\u51b5\uff1a<\/p>\n<ul type=\"disc\">\n<li>\u5982\u679c\u8be5\u95ee\u9898\u4e0d\u53ef\u5206\uff0c\u90a3\u4e48n-2\u4ef6v\u4ecd\u7136\u4e0d\u53ef\u5206\uff0c\u4f9d\u6b21\u7c7b\u63a8\uff0c\u7528s\u6216 s-1\u66ff\u6362n\u4ecd\u7136\u4e0d\u53ef\u5206<\/li>\n<\/ul>\n<ul type=\"disc\">\n<li>\u5982\u679c\u8be5\u95ee\u9898\u53ef\u5206\uff0c\u5373\u53ef\u5206\u6210\u4ef7\u503c\u76f8\u7b49\u7684\u4e24\u5806\u3002\u5206\u4e24\u79cd\u60c5\u51b5\u8003\u8651\uff1a<\/li>\n<\/ul>\n<ul type=\"square\">\n<li>\u5982\u679c\u4e24\u5806\u91cc\u90fd\u6709v\u3002 \u4e24\u5806\u5404\u51cf\u4e00\u4e2av\uff0c\u5373n\u6539\u4e3an-2,\u4ecd\u7136\u53ef\u5206\uff0c\u53ef\u4ee5\u53cd\u590d\u51cf2\u76f4\u81f3\u53ea\u6709\u4e00\u5806\u6709v\u3002<\/li>\n<\/ul>\n<ul type=\"square\">\n<li>\u5982\u679c\u4ec5\u6709\u4e00\u5806\u6709v\u3002 \u5982\u679c\u5c06n\u6539\u4e3an-2\u4ecd\u53ef\u5206\uff0c\u5219\u5fc5\u987b\u6ee1\u8db3\u4e24\u4e2a\u6761\u4ef6\uff1a I.\u6ca1\u6709v\u7684\u90a3\u4e00\u5806\u4e2d\uff0c\u81f3\u5c11\u6709\u4e00\u79cd\u5176\u5b83\u7269\u54c1\u53ef\u66ff\u6362v\u3002II.\u66ff\u6362\u540e\u4e24\u5806\u90fd\u81f3\u5c11\u6709\u4e00\u4e2av\u3002\u5982\u679cn&gt;s\u65f6\u59cb\u7ec8\u6ee1\u8db3\u8fd9\u4e24\u4e2a\u6761\u4ef6\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u7528s\u6216s-1\u66ff\u6362n.<\/li>\n<\/ul>\n<p>\u4e0b\u9762\u4f9d\u6b21\u8003\u8651v=1,2,3,4,5,6\u65f6\u5982\u4f55\u6839\u636e\u201c\u62bd\u5c49\u539f\u7406\u201d\u5f97\u5230\u6ee1\u8db3\u6761\u4ef6I\u548cII\u7684s\u3002<\/p>\n<p>v=1\u65f6\uff0cs=6 \u66ff\u6362\u6cd5\uff1a if(n&gt;6) n=6-n%2<\/p>\n<p>1\u603b\u80fd\u88ab\u5176\u5b83\u4ef7\u503c\u66ff\u6362\uff0c\u6240\u4ee5\u6ee1\u8db3\u6761\u4ef6I\u4e0d\u662f\u95ee\u9898\uff0c\u4e3a\u6ee1\u8db3\u6761\u4ef62\uff0cs\u5fc5\u987b\u5927\u4e8e6\u3002 \u56e0\u4e3a6\u662f\u5176\u5b83\u4ef7\u503c\u7269\u54c1\u4e2d\u4e00\u6b21\u53ef\u66ff\u6362\u6700\u591a1\u7684\u7269\u54c1\u3002<\/p>\n<p>v=2\u65f6\uff0cs=5 \u66ff\u6362\u6cd5\uff1a if(n&gt;5) n=4+n%2<\/p>\n<p>\u75311*(2-1)+3*(2-1)+4*(1-1)+5*(2-1)+6*(1-1) = 9 &lt; 2*5\u77e5\uff0cs=4\u65f6\u6ee1\u8db3\u6761\u4ef6I\u3002\u4f46\u8fd9\u91cc\u8981\u6ce8\u610f\uff0c\u5982\u679c\u53e6\u4e00\u5806\u53ef\u66ff\u63622\u7684\u662f\u4e24\u4e2a5\uff0c\u90a3\u4e48\u4e00\u6b21\u5c31\u53ef\u66ff\u63625\u4e2a2\u3002\u4e3a\u6ee1\u8db3\u6761\u4ef6 II,s\u4e0d\u80fd\u5c0f\u4e8e5\u3002\u6240\u4ee5\u8fd9\u91ccs\u662f5\u800c\u4e0d\u662f4\u3002<\/p>\n<p>v=3\u65f6\uff0cs=8 \u66ff\u6362\u6cd5\uff1a if(n&gt;8) n=8-n%2<\/p>\n<p>\u75311*(3-1)+2*(3-1)+4*(3-1)+5*(3-1)+6*(1-1) = 24 &lt; 3*9\u77e5\uff0cs=8\u65f6\u6ee1\u8db3\u6761\u4ef6I\uff0c\u4e14\u6700\u591a\u53ef\u66ff\u63625\u4e2a3\uff0c\u6240\u4ee5s=8&gt;5\u4e5f\u6ee1\u8db3\u6761\u4ef6II\u3002<\/p>\n<p>v=4\u65f6\uff0cs=8 \u66ff\u6362\u6cd5\uff1a if(n&gt;8) n=8-n%2<\/p>\n<p>\u75311*(4-1)+2*(2-1)+3*(4-1)+5*(4-1)+6*(2-1) = 35 &lt; 4*9\u77e5\uff0c s=8\u65f6\u6ee1\u8db3\u6761\u4ef6I\uff0c\u4e14\u6700\u591a\u53ef\u66ff\u63625\u4e2a4\uff0c\u6240\u4ee5s=8&gt;5\u4e5f\u6ee1\u8db3\u6761\u4ef6II\u3002<\/p>\n<p>v=5\u65f6\uff0cs=12 \u66ff\u6362\u6cd5\uff1a if(n&gt;12) n=12-n%2<\/p>\n<p>\u75311*(5-1)+2*(5-1)+3*(5-1)+4*(5-1)+6*(5-1) = 64 &lt; 5*13\u77e5\uff0cs=12\u6ee1\u8db3\u6761\u4ef6I\uff0c\u4e14\u6700\u591a\u53ef\u66ff\u63626\u4e2a5\uff0c\u6240\u4ee5s=12&gt;6\u4e5f\u6ee1\u8db3\u6761\u4ef6II\u3002<\/p>\n<p>v=6\u65f6\uff0cs=7 \u66ff\u6362\u6cd5\uff1aif(n&gt;7) n=6+n%2<\/p>\n<p>\u75311*(6-1)+2*(3-1)+3*(2-1)+4*(3-1)+5*(6-1) = 45 &lt; 6*8\u77e5\uff0cs=7\u6ee1\u8db3\u6761\u4ef6I\uff0c\u4e14\u6700\u591a\u53ef\u66ff\u63625\u4e2a6\uff0c\u6240\u4ee5s=7&gt;5\u4e5f\u6ee1\u8db3\u6761\u4ef6II\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u51fa\uff0c\u201c\u6a21\u4f18\u5316\u201d\u5c06\u65e0\u8bba\u591a\u4e48\u5927\u7684\u8f93\u5165\u6837\u672c\u51cf\u5c11\u523050\u4e2a\u4ee5\u5185\uff0c\u6781\u5927\u5730\u51cf\u5c11\u4e86\u8ba1\u7b97\u91cf\uff0c\u4ece\u800c\u663e\u8457\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\u3002\u800c\u201c\u6a21\u4f18\u5316\u201d\u7684\u5173\u952e\u5c31\u662f\u201c\u62bd\u5c49\u539f\u7406\u201d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u95ee\u9898\u63cf\u8ff0\uff1a \u6709\u82e5\u5e72\u4ef7\u503c\u4e3a\u5206\u522b\u4e3a1\uff0c2 \uff0c3\uff0c4\uff0c5\uff0c6\u7684\u5927\u7406\u77f3\uff0c\u6c42 &hellip; <a href=\"https:\/\/blog.rexdf.org\/ja\/2011\/10\/poj1014-%e5%a4%9a%e9%87%8d%e8%83%8c%e5%8c%85-%e4%ba%8c%e8%bf%9b%e5%88%b6%e4%bc%98%e5%8c%96-%e5%8f%96%e6%a8%a1%e4%bc%98%e5%8c%96\/\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":12,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23],"tags":[212,89],"class_list":["post-62","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-23","tag-212","tag-89"],"jetpack_featured_media_url":"https:\/\/static.rexdf.org\/uploads\/2011\/10\/1280wallpaperQ11.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":0,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/media\/12"}],"wp:attachment":[{"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.rexdf.org\/ja\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}