{"id":310,"date":"2011-12-17T20:05:10","date_gmt":"2011-12-17T12:05:10","guid":{"rendered":"http:\/\/ykyi.net\/?p=310"},"modified":"2011-12-17T20:05:10","modified_gmt":"2011-12-17T12:05:10","slug":"sicily-2014-dairy-queen-%e8%a7%a3%e9%a2%98%e6%8a%a5%e5%91%8a","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=310","title":{"rendered":"sicily 2014. Dairy Queen \u89e3\u9898\u62a5\u544a"},"content":{"rendered":"<div>\n<p>Sun Yat-sen University ACM 2014. Dairy Queen<\/p>\n<p>1.&nbsp;\u539f\u9898\u4e2d\u6587\u5927\u610f<span style=\"font-family: Times New Roman;\">;<\/span><\/p>\n<p>\u7ed9\u51fa\u4e00\u4e2a\u5728&nbsp;<span style=\"font-family: Times New Roman;\">[1,&nbsp;300]&nbsp;<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e4b\u95f4\u7684\u6570\u5b57<\/span><span style=\"font-family: Times New Roman;\">N<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002\u7136\u540e\u7ed9\u51fa\u4e00\u4e2a\u96c6\u5408\uff0c\u8fd9\u4e2a\u96c6\u5408\u4e2d\u6709<\/span><span style=\"font-family: Times New Roman;\">C&nbsp;<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e2a\u6570\u5b57\uff0c<\/span><span style=\"font-family: Times New Roman;\">C<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u5728<\/span><span style=\"font-family: Times New Roman;\">[1,&nbsp;8]<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e4b\u95f4\u3002\u8be5\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u5728<\/span><span style=\"font-family: Times New Roman;\">[1,&nbsp;200]<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e4b\u95f4\u3002\u95ee\u5982\u4f55\u7528\u8fd9\u4e2a\u96c6\u5408\u4e2d\u7684\u6570\u5b57\u7ec4\u5408\uff08\u6570\u5b57\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff09\uff0c\u4f7f\u5b83\u4eec\u7684\u603b\u548c\u7b49\u4e8e<\/span><span style=\"font-family: Times New Roman;\">N<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002<\/span><\/p>\n<p>2.&nbsp;<span style=\"font-family: \u5b8b\u4f53;\">\u89e3\u8fd9\u79cd\u9898\u6beb\u4e0d\u72b9\u8c6b\u5730\u60f3\u5230\u7528\u52a8\u6001\u89c4\u5212\u3002<\/span><\/p>\n<p>3.&nbsp;<span style=\"font-family: \u5b8b\u4f53;\">\u8bbe\u4e00\u4e2a\u6570\u7ec4&nbsp;<\/span><span style=\"font-family: Times New Roman;\">ways[301];&nbsp;ways[n]<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u8868\u793a\u6709\u591a\u5c11\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ec4\u5408\u6210\u548c<\/span><span style=\"font-family: Times New Roman;\">n<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002\u5047\u8bbe\u96c6\u5408\u4e2d\u53ea\u4e00\u4e2a\u6570\u5b57<\/span><span style=\"font-family: Times New Roman;\">x<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002\u90a3\u4e48\u95ee\u9898\u5c31\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u80fd\u53d6<\/span><span style=\"font-family: Times New Roman;\">n<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e2a\u8be5\u6570\u5b57\uff0c\u548c\u7684\u96c6\u5408\u4e3a<\/span><span style=\"font-family: Times New Roman;\">{x,&nbsp;2x,&nbsp;3x}<\/span><span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u5373<\/span><span style=\"font-family: Times New Roman;\">ways[x]=1<\/span><span style=\"font-family: \u5b8b\u4f53;\">\uff0c<\/span><span style=\"font-family: Times New Roman;\">ways[2x]=1,&nbsp;ways[3x]=1&nbsp;&#8230;.<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002\u5982\u679c\u96c6\u5408\u4e2d\u6709<\/span><span style=\"font-family: Times New Roman;\">m<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u6570\u5b57\uff0c\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u6c42\u5f97\u4e86\u7528\u8fd9<\/span><span style=\"font-family: Times New Roman;\">m<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e2a\u6570\u5b57\u7684\u7ec4\u5408\u53ef\u4ee5\u5f97\u5230\u7684\u548c\u7684\u6570\u76ee\u5b58\u5230\u4e86<\/span><span style=\"font-family: Times New Roman;\">ways<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u6570\u7ec4\u91cc\u3002\u5373\u5bf9\u4e8e<\/span><span style=\"font-family: Times New Roman;\">m<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e2a\u6570\u5b57\uff0c\u5df2\u6c42\u5f97&nbsp;<\/span><span style=\"font-family: Times New Roman;\">ways[1]&nbsp;=&nbsp;?,&nbsp;ways[2]&nbsp;=&nbsp;?,&nbsp;ways[3]&nbsp;=&nbsp;?&nbsp;&#8230;..&nbsp;Ways[300]&nbsp;=&nbsp;?<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002&nbsp;\u90a3\u4e48\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u518d\u52a0\u591a\u4e00\u4e2a\u6570\u5b57\uff0c\u5373&nbsp;<\/span><span style=\"font-family: Times New Roman;\">m+1<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e2a\u6570\u5b57\u7684\u60c5\u51b5\u4f1a\u662f\u5982\u4f55\u5462\u3002\u8bbe\u65b0\u52a0\u5165\u7684\u8fd9\u4e2a\u6570\u5b57\u7684\u503c\u662f<\/span><span style=\"font-family: Times New Roman;\">p<\/span><span style=\"font-family: \u5b8b\u4f53;\">\uff0c\u5219\u5e94\u8be5\u662f&nbsp;<\/span><span style=\"font-family: Times New Roman;\">ways[q]&nbsp;+=&nbsp;ways[q-p]<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u3002\uff08<\/span><span style=\"font-family: Times New Roman;\">q&nbsp;&gt;&nbsp;p<\/span><span style=\"font-family: \u5b8b\u4f53;\">\uff09<\/span><\/p>\n<p>&nbsp;<\/p>\n<p>4.&nbsp;\u7a0b\u5e8f\u6ce8\u91ca\u6e05\u5355.<\/p>\n<pre class=\"brush:cpp\">#include &lt;string.h&gt;\n\n#include &lt;stdlib.h&gt;\n\n#include &lt;stdio.h&gt;\n\n\n\nint main(int argc, char* argv[])\n\n{\n\nint N, C, coin;  \/\/ N\u4e3a\u9898\u610f\u4e2d\u7684N\uff0cC\u5373\u9898\u610f\u4e2d\u7684C. coin\u4f5c\u4e34\u65f6\u53d8\u91cf\u7528\uff0c\u4e0d\u89e3\u91ca\uff0c\u53ef\u89c1\u4e0b\u9762\u7684\u4ee3\u7801\u3002\n\nint ways[301] = { 0 };  \/\/ \u89c1\u7b2c\u4e09\u90e8\u5206\u7684\u5206\u6790\u3002\n\nways[0] = 1;  \/\/ \u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u3002\u4e3a\u4e86\u65b9\u4fbf\u8ba1\u7b97.\n\n\n\nscanf(&quot;%d %d&quot;, &amp;N, &amp;C);\n\nfor ( int i = 0; i &lt; C; i++)\n\n{\n\nscanf(&quot;%d&quot;, &amp;coin);\n\nfor ( int j = coin; j &lt;= N; j++ )\n\n{\n\nways[j] += ways[j-coin];  \/\/ \u89c1\u7b2c3\u90e8\u5206\u7684\u5206\u6790.\n\n}\n\n}\n\nprintf(&quot;%d\\n&quot;, ways[N]);\n\n\n\nreturn 0;\n\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>5.\u65f6\u95f4\u590d\u6742\u5ea6\uff0c\u7a7a\u95f4\u590d\u6742\u5ea6\u5206\u6790\u3002<\/p>\n<p>\u7a7a\u95f4\u590d\u6742\u5ea6\u662f\u786e\u5b9a\u7684\u5e38\u6570\u3002\u65f6\u95f4\u590d\u6742\u5ea6\u662f<span style=\"font-family: Times New Roman;\">o(n).&nbsp;n<\/span><span style=\"font-family: \u5b8b\u4f53;\">\u4e3a\u6709\u591a\u5c11\u79cd\u9762\u503c\u7684\u786c\u5e01\u3002<\/span><\/p>\n<p><a href=\"http:\/\/ykyi.net\">http:\/\/ykyi.net<\/a> zausiu&#39;s blog<\/p>\n<p>\u539f\u9898\uff1a<\/p>\n<h1>Description<\/h1>\n<p>Bessie, always in need of an income, has decided to leverage her dairy skills by taking a part-time job at the local Dairy Queen restaurant. She is running a special cash register (since she has hooves instead of fingers and thus requires special accommodation). Her job is making change for customers as they make a purchase.<\/p>\n<p>As she was counting out 83 cents in change, she wondered: &quot;How many ways can I count out 83 cents? I can use three quarters and eight pennies, seven dimes and three pennies, 83 pennies&#8230; there must be a zillion ways!&quot;<\/p>\n<p>How many different ways can one make change for N (1 &le; N &le; 300) cents using coins from a set of C (1 &le; C &le; 8) coins of supplied values C_i (1 &le; C_i &le; 200)? &quot;Different&quot; means differing counts of coins.<\/p>\n<p>Thus, 8 cents can be made, in American currency, with 1 five-cent piece + 3 one-cent pieces and also with 8 one-cent pieces. Using 3 one-cent pieces + 1 five-cent piece is the same as 1 five-cent piece + 3 one-cent pieces, so one can create eight cents in just two different ways. Note that some coin systems are poor at making change and result in an answer of &#39;0&#39;.<\/p>\n<p>Coin values in the input file are listed in descending order from largest to smallest. All coin values will be distinct.<\/p>\n<h1>Input<\/h1>\n<p>&nbsp;<\/p>\n<p>Line 1: Two space-separated integers: N and C<br \/>\n\t\tLines 2..C+1: Line i+1 contains a single integer: C_i<\/p>\n<p>&nbsp;<\/p>\n<h1>Output<\/h1>\n<p>Line 1: A single line with a single integer that is the number of ways to create N cents of change using the supplied coins. The answer is guaranteed to fit into a signed 32-bit int<\/p>\n<p>&nbsp;<\/p>\n<h1>Sample Input<\/h1>\n<pre>83 5\n50\n25\n10\n5\n1<\/pre>\n<h1>Sample Output<\/h1>\n<pre>159<\/pre>\n<p>&nbsp;<\/p>\n<p>copyright ykyi.net<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sun Yat-sen University ACM 2014. Dairy Queen 1.&nbsp;\u539f\u9898\u4e2d\u6587\u5927\u610f; \u7ed9\u51fa\u4e00\u4e2a\u5728&nbsp;[1,&nbsp;300]&nbsp;\u4e4b\u95f4\u7684\u6570\u5b57N\u3002\u7136\u540e\u7ed9\u51fa\u4e00\u4e2a\u96c6\u5408\uff0c\u8fd9\u4e2a\u96c6\u5408\u4e2d\u6709C&nbsp;\u4e2a\u6570\u5b57\uff0cC\u5728[1,&nbsp;8]\u4e4b\u95f4\u3002\u8be5\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u6570\u5b57\u5728[1,&nbsp;200]\u4e4b\u95f4\u3002\u95ee\u5982\u4f55\u7528\u8fd9\u4e2a\u96c6\u5408\u4e2d\u7684\u6570\u5b57\u7ec4\u5408\uff08\u6570\u5b57\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\uff09\uff0c\u4f7f\u5b83\u4eec\u7684\u603b\u548c\u7b49\u4e8eN\u3002 2.&nbsp;\u89e3\u8fd9\u79cd\u9898\u6beb\u4e0d\u72b9\u8c6b\u5730\u60f3\u5230\u7528\u52a8\u6001\u89c4\u5212\u3002 3.&nbsp;\u8bbe\u4e00\u4e2a\u6570\u7ec4&nbsp;ways[301];&nbsp;ways[n]\u8868\u793a\u6709\u591a\u5c11\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7ec4\u5408\u6210\u548cn\u3002\u5047\u8bbe\u96c6\u5408\u4e2d\u53ea\u4e00\u4e2a\u6570\u5b57x\u3002\u90a3\u4e48\u95ee\u9898\u5c31\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u80fd\u53d6n\u4e2a\u8be5\u6570\u5b57\uff0c\u548c\u7684\u96c6\u5408\u4e3a{x,&nbsp;2x,&nbsp;3x}\uff0c\u5373ways[x]=1\uff0cways[2x]=1,&nbsp;ways[3x]=1&nbsp;&#8230;.\u3002\u5982\u679c\u96c6\u5408\u4e2d\u6709m\u6570\u5b57\uff0c\u5047\u8bbe\u6211\u4eec\u5df2\u7ecf\u6c42\u5f97\u4e86\u7528\u8fd9m\u4e2a\u6570\u5b57\u7684\u7ec4\u5408\u53ef\u4ee5\u5f97\u5230\u7684\u548c\u7684\u6570\u76ee\u5b58\u5230\u4e86ways\u6570\u7ec4\u91cc\u3002\u5373\u5bf9\u4e8em\u4e2a\u6570\u5b57\uff0c\u5df2\u6c42\u5f97&nbsp;ways[1]&nbsp;=&nbsp;?,&nbsp;ways[2]&nbsp;=&nbsp;?,&nbsp;ways[3]&nbsp;=&nbsp;?&nbsp;&#8230;..&nbsp;Ways[300]&nbsp;=&nbsp;?\u3002&nbsp;\u90a3\u4e48\u5728\u6b64\u57fa\u7840\u4e0a\uff0c\u518d\u52a0\u591a\u4e00\u4e2a\u6570\u5b57\uff0c\u5373&nbsp;m+1\u4e2a\u6570\u5b57\u7684\u60c5\u51b5\u4f1a\u662f\u5982\u4f55\u5462\u3002\u8bbe\u65b0\u52a0\u5165\u7684\u8fd9\u4e2a\u6570\u5b57\u7684\u503c\u662fp\uff0c\u5219\u5e94\u8be5\u662f&nbsp;ways[q]&nbsp;+=&nbsp;ways[q-p]\u3002\uff08q&nbsp;&gt;&nbsp;p\uff09 &nbsp; 4.&nbsp;\u7a0b\u5e8f\u6ce8\u91ca\u6e05\u5355. #include &lt;string.h&gt; #include &lt;stdlib.h&gt; #include &lt;stdio.h&gt; int main(int argc, char* argv[]) { int N, C, coin; \/\/ N\u4e3a\u9898\u610f\u4e2d\u7684N\uff0cC\u5373\u9898\u610f\u4e2d\u7684C. coin\u4f5c\u4e34\u65f6\u53d8\u91cf\u7528\uff0c\u4e0d\u89e3\u91ca\uff0c\u53ef\u89c1\u4e0b\u9762\u7684\u4ee3\u7801\u3002 int ways[301] = { 0 }; \/\/ \u89c1\u7b2c\u4e09\u90e8\u5206\u7684\u5206\u6790\u3002 ways[0] = 1; \/\/ \u6ca1\u6709\u5b9e\u9645\u610f\u4e49\u3002\u4e3a\u4e86\u65b9\u4fbf\u8ba1\u7b97. scanf(&quot;%d %d&quot;, &amp;N, &amp;C); for ( int i = 0; &hellip; <a href=\"https:\/\/ykyi.net\/?p=310\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;sicily 2014. Dairy Queen \u89e3\u9898\u62a5\u544a&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[108],"class_list":["post-310","post","type-post","status-publish","format-standard","hentry","category-tech_articles","tag-108"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/310","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=310"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/310\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}