{"id":5422,"date":"2021-07-20T10:57:45","date_gmt":"2021-07-20T02:57:45","guid":{"rendered":"https:\/\/damogame.cn\/wordpress\/?p=5422"},"modified":"2021-07-20T12:15:30","modified_gmt":"2021-07-20T04:15:30","slug":"%e8%b4%a7%e5%b8%81%e6%89%be%e9%9b%b6%e9%97%ae%e9%a2%98%e6%b1%82%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/i007.cc\/wordpress\/archives\/5422","title":{"rendered":"\u8d27\u5e01\u627e\u96f6\u95ee\u9898\u6c42\u89e3"},"content":{"rendered":"<p>\u5b9e\u7528\u52a8\u6001\u89c4\u5212+\u7f13\u5b58\uff0c\u5b8c\u7f8e\u89e3\u51b3<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#include &lt;stdio.h&gt;\r\n#include &lt;vector&gt;\r\n#include &lt;map&gt;\r\n\r\n\/*\r\n\u8003\u8651\u5e01\u503c\u4e3a 100 \uff0c 99 \u548c 1 \u7684\u5e01\u79cd\uff0c\u6bcf\u79cd\u5404\u4e00\u767e\u5f20\uff0c\u627e 396 \u5143\r\n*\/\r\n\r\nclass Solution {\r\npublic:\r\n    std::vector&lt;int&gt; GetResult(const std::vector&lt;int&gt;&amp; cash, int target) {\r\n        std::map&lt;int, std::vector&lt;int&gt;&gt; cache;\r\n        return get_result(cash, target, cache);\r\n    }\r\n\r\n    std::vector&lt;int&gt; get_result(const std::vector&lt;int&gt;&amp; cash, int target, std::map&lt;int, std::vector&lt;int&gt;&gt;&amp; cache) {\r\n        if (target &lt;= 0)\r\n            return std::vector&lt;int&gt;();\r\n\r\n        for (auto i : cash) {\r\n            if (target == i) {\r\n                return std::vector&lt;int&gt;(1, i);\r\n            }\r\n        }\r\n\r\n        auto it = cache.find(target);\r\n        if (it != cache.end()) {\r\n            return it-&gt;second;\r\n        }\r\n\r\n        std::vector&lt;int&gt; result;\r\n        for (auto i : cash) {\r\n            auto this_result = get_result(cash, target - i, cache);\r\n            if (this_result.size() == 0)\r\n                continue;\r\n\r\n            this_result.push_back(i);\r\n            if (result.size() == 0) {\r\n                result = this_result;\r\n            } else if (this_result.size() &lt; result.size()) {\r\n                result = this_result;\r\n            }\r\n        }\r\n\r\n        cache[target] = result;\r\n        return result;\r\n    }\r\n};\r\n\r\nint main() {\r\n    std::vector&lt;int&gt; cash;\r\n    cash.push_back(1);\r\n    cash.push_back(99);\r\n    cash.push_back(100);\r\n\r\n    auto ret = Solution().GetResult(cash, 396);\r\n    return 0;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u7528\u52a8\u6001\u89c4\u5212+\u7f13\u5b58\uff0c\u5b8c\u7f8e\u89e3\u51b3 &#038;nbsp<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[],"tags":[120],"class_list":["post-5422","post","type-post","status-publish","format-standard","hentry","tag-04-"],"_links":{"self":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5422","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/comments?post=5422"}],"version-history":[{"count":0,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/posts\/5422\/revisions"}],"wp:attachment":[{"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/media?parent=5422"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/categories?post=5422"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/i007.cc\/wordpress\/wp-json\/wp\/v2\/tags?post=5422"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}