{"id":48,"date":"2023-02-02T13:15:00","date_gmt":"2023-02-02T05:15:00","guid":{"rendered":"https:\/\/solost.cn\/?p=48"},"modified":"2023-02-02T13:28:08","modified_gmt":"2023-02-02T05:28:08","slug":"110","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=48","title":{"rendered":"2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84255-L-\u5c0f\u6c99\u306e\u62b1\u56e2 hard"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/image1.png\" alt=\"\" title=\"\"><\/p>\n<h2>solution<\/h2>\n<ul>\n<li>\u56e0\u4e3a\u627e\u6700\u5c0f\u4ee3\u4ef7\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u6570\u7ec4\u4e3a\u6700\u5927<\/li>\n<li>\u6211\u4eec\u53ef\u4ee5\u5f88\u5feb\u5f97\u77e5\uff0c\u6700\u5927\u72b6\u6001\u4e5f\u5c31\u662fn\u7684\u4ee3\u4ef7\u662f\u56fa\u5b9a\u7684\uff0c\u6700\u5c0f\u4ee3\u4ef7\u4e0d\u786e\u5b9a\uff0c\u6240\u4ee5\u6211\u4eec\u4ece\u5927\u5230\u5c0f\u63a8<\/li>\n<li>\u6211\u4eec\u7528\u4e00\u7ef4\u6570\u7ec4\u6765dp,f[i]\u4ee3\u8868\u4ecen\u5230\u8fbei\u65f6\u7684\u4ee3\u4ef7\u3002<\/li>\n<li>\u90a3\u4e48\u8f6c\u79fb\u65b9\u7a0b\u5c31\u662f<code>f[i - i % v[j]] = min(f[i - i % v[j], f[i] + w[i]]<\/code>,\u53cd\u63a8\u6bd4\u8f83\u597d\u63a8\u51fa\u6765\uff0c\u5426\u5219\u6b63\u63a8\u5bf9\u5e94\u60c5\u51b5\u6709\u70b9\u591a\u3002<\/li>\n<\/ul>\n<pre><code class=\"lang-cpp\">#include &lt;algorithm&gt;\n#include &lt;bitset&gt;\n#include &lt;cmath&gt;\n#include &lt;cstdio&gt;\n#include &lt;cstdlib&gt;\n#include &lt;cstring&gt;\n#include &lt;fstream&gt;\n#include &lt;iostream&gt;\n#include &lt;map&gt;\n#include &lt;queue&gt;\n#include &lt;set&gt;\n#include &lt;stack&gt;\n#include &lt;unordered_map&gt;\n#include &lt;vector&gt;\n\nusing namespace std;\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\ntypedef long long ll;\ntypedef pair&lt;int, int&gt; PII;\ntypedef unsigned long long ull;\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 2e5 + 10;\nint n, m;\nint v[N], w[N];\nint f[N];\nint main()\n{\n    memset(f, 0x3f, sizeof f);\n    cin &gt;&gt; n &gt;&gt; m;\n\n    for (int i = 1; i &lt;= m; i++) {\n        cin &gt;&gt; w[i] &gt;&gt; v[i];\n    }\n  \n    memset(f, 0x3f, sizeof f);\n    f[n] = 0;\n    for(int i = n; i &gt;= 0; i--){\n        if(f[i] == INF) continue;\n        for(int j = 1; j &lt;= m; j++){\n            if(i &lt; v[j]) continue;\n            f[i - i % v[j]] = min(f[i - i % v[j]], f[i] + w[j]);\n        }\n    }\n    int i = 1;\n    while(f[i] == INF) i++;\n    cout &lt;&lt; f[i];\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>solution \u56e0\u4e3a\u627e\u6700\u5c0f\u4ee3\u4ef7\uff0c\u6240\u4ee5\u521d\u59cb\u5316\u6570\u7ec4\u4e3a\u6700\u5927 \u6211\u4eec\u53ef\u4ee5\u5f88\u5feb\u5f97\u77e5\uff0c\u6700\u5927\u72b6\u6001\u4e5f\u5c31\u662fn\u7684\u4ee3\u4ef7\u662f\u56fa\u5b9a\u7684\uff0c\u6700\u5c0f\u4ee3\u4ef7\u4e0d\u786e\u5b9a\uff0c\u6240\u4ee5\u6211\u4eec\u4ece\u5927\u5230\u5c0f\u63a8 \u6211\u4eec\u7528\u4e00\u7ef4\u6570\u7ec4\u6765dp,f[i]\u4ee3\u8868\u4ecen\u5230\u8fbei\u65f6\u7684\u4ee3\u4ef7\u3002 \u90a3\u4e48\u8f6c\u79fb\u65b9\u7a0b\u5c31\u662ff[i - i % v[j]] = min(f[i - i % v[j], f[i] + w[i]],\u53cd\u63a8\u6bd4\u8f83\u597d\u63a8\u51fa\u6765\uff0c\u5426\u5219\u6b63\u63a8\u5bf9\u5e94\u60c5\u51b5\u6709\u70b9\u591a\u3002 #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;map&gt; #include &lt;queue&gt; #include &lt;set&gt; #include &lt;stack&gt; #include &lt;unordered_map&gt; #include &lt;vector&gt; using namespace std; #define endl &#039;\\n&#039; #define IOS \\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[18],"class_list":["post-48","post","type-post","status-publish","format-standard","hentry","category-solution","tag-18"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/48","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=48"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/48\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=48"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=48"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=48"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}