{"id":34,"date":"2023-01-30T20:03:00","date_gmt":"2023-01-30T12:03:00","guid":{"rendered":"https:\/\/solost.cn\/?p=34"},"modified":"2023-02-02T16:49:24","modified_gmt":"2023-02-02T08:49:24","slug":"69","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=34","title":{"rendered":"2023\u725b\u5ba2\u5bd2\u5047\u7b97\u6cd5\u57fa\u7840\u96c6\u8bad\u84254-\u6e05\u695a\u59d0\u59d0\u5b6601\u80cc\u5305(Easy Version)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/11\/4234256143.png\" alt=\"\" title=\"\"><\/p>\n<h2>solution<\/h2>\n<p>\u9898\u76ee\u5927\u610f\uff0c\u8fd9\u9053\u9898\u7684\u610f\u601d\u662f\u80cc\u5305\u5927\u5c0f\u662fm,\u6709n\u4ef6\u7269\u54c1\uff0c\u6700\u4f18\u53d6\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u53bb\u6389\u8fd9\u4ef6\u7269\u54c1\uff0c\u80fd\u4ea7\u751f\u7684\u6700\u5927\u4ef7\u503c\u4e0e\u4e0d\u53bb\u6389\u65f6\u5019\u7684\u4ef7\u503c\u5dee\u591a\u5c11\u3002<\/p>\n<p>\u9996\u5148\u4f7f\u752801\u80cc\u5305\u628a\u6700\u4f18\u60c5\u51b5\u7b97\u51fa\u6765\uff0c\u7136\u540e\u53bb\u6389\u7b2ci\u4ef6\u7269\u54c1\uff0c\u770b\u770b\u5dee\u503c\u3002<\/p>\n<pre><code class=\"C++\">#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 = 110;\nll v[N], w[N], f[N];\/\/f\u6570\u7ec4\u4ee3\u8868\u6700\u5927\u4ef7\u503c\nll dp[N][N];\/\/dp\u6570\u7ec4\u4ee3\u8868\u5728\u5bb9\u91cf\u4e3ai,\u53bb\u6389\u7b2cj\u4ef6\u7269\u54c1\u65f6\u7684\u6700\u5927\u503c,dp[i][j]\nll n, m;\nint main()\n{\n    cin &gt;&gt; n &gt;&gt; m;\n    for (int i = 1; i &lt;= n; i++) {\n        cin &gt;&gt; v[i] &gt;&gt; w[i];\n    }\n\n    for (int i = 1; i &lt;= n; i++) {\n        for (int j = m; j &gt;= v[i]; j--) {\n            f[j] = max(f[j], f[j - v[i]] + w[i]);\n        }\n    }\n  \n    for(int k = 1; k &lt;= n; k++){\n        ll t = w[k];\n        w[k] = 0;\n        for(int i = 1; i &lt;= n; i++){\n            for(int j = m; j &gt;= v[i]; j--){\n                dp[j][k] = max(dp[j][k], dp[j - v[i]][k] + w[i]);\n            }\n        }\n        w[k] = t;\n    }\n    for(int i = 1; i &lt;= n; i++){\n        if(f[m] &gt; dp[m][i]) cout &lt;&lt; &quot;0\\n&quot;;\/\/\u5982\u679c\u53bb\u6389\u4e86\u8fd9\u4ef6\u7269\u54c1\uff0c\u90a3\u4e48\u4ed6\u5c31\u5c0f\u4e8e\u6700\u4f18\u60c5\u51b5\uff0c\u4ed6\u5c31\u662f\u5fc5\u9009\n        else{\/\/\u5426\u5219\u8f93\u51fa\u6700\u4f18\u51cf\u53bb\u4e0d\u5305\u62ec\u7b2ci\u4ef6\u7269\u54c1\u7684\u65f6\u5019\uff0c\u8bb0\u5f97\u52a01\uff0c\u56e0\u4e3a\u8981\u5927\u4e8e\n            cout &lt;&lt; f[m] - dp[m - v[i]][i] + 1 - w[i] &lt;&lt; endl;\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n<p>\u7b2c\u4e8c\u79cd\u89e3\u6cd5<\/p>\n<pre><code class=\"lang-cpp\">#include&lt;map&gt;\n#include&lt;set&gt;\n#include&lt;stack&gt;\n#include&lt;queue&gt;\n#include&lt;cmath&gt;\n#include&lt;vector&gt;\n#include&lt;bitset&gt;\n#include&lt;cstdio&gt;\n#include&lt;cstring&gt;\n#include&lt;fstream&gt;\n#include&lt;cstdlib&gt;\n#include&lt;iostream&gt;\n#include&lt;algorithm&gt;\n#include&lt;unordered_map&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 = 2e3 + 10;\nll v[N], w[N], f[N];\nint n, m;\nint main(){\n    cin &gt;&gt; n &gt;&gt; m;\n    for(int i = 1; i &lt;= n; i ++ ) cin &gt;&gt; v[i] &gt;&gt; w[i];\n    for(int i = 1; i &lt;= n; i ++)\n        for(int j = m; j &gt;= v[i]; j --){\n            f[j] = max(f[j], f[j - v[i]] + w[i]);\n        }\n    ll ans = f[m];\/\/\u5148\u8ba1\u7b97\u51fa\u6700\u4f18\u7684\n    for(int k = 1; k &lt;= n; k++){\n        ll t = w[k];\n        w[k] = 0;\/\/\u5148\u628a\u4ed6\u7684\u4ef7\u503c\u5f52\u96f6\uff0c\u4ed6\u80af\u5b9a\u4e0d\u4f1a\u53d6\n        memset(f, 0, sizeof f);\/\/\u6bcf\u6b21\u5fc5\u987b\u521d\u59cb\u5316\uff0c\u8981\u4e0d\u7136\u5148\u524d\u7684\u503c\u4f1a\u66f4\u65b0\n        for(int i = 1; i &lt;= n; i++){\n            for(int j = m; j &gt;= v[i]; j--){\n                f[j] = max(f[j], f[j - v[i]] + w[i]);\n            }\n        } \n        w[k] = t;\/\/\u7136\u540e\u628a\u8fd9\u4e2a\u503c\u518d\u653e\u56de\u53bb\uff0c\u7b49\u5f85\u4e0b\u4e00\u6b21\u7684\n        if(ans &gt; f[m]) cout &lt;&lt; &quot;0\\n&quot;;\/\/\u5982\u679c\u4e0d\u53d6\u7b2ck\u4ef6\uff0c\u4ed6\u6bd4\u6700\u4f18\u5c0f\uff0c\u8bc1\u660e\u4ed6\u662f\u5fc5\u9009\u7684\n        else{\n            cout &lt;&lt; ans - f[m - v[k]] + 1 - w[k] &lt;&lt; endl;\n        \/\/\u5426\u5219\u6700\u4f18\u7684\u51cf\u53bb\u4e0d\u5305\u62ecv[k]\u65f6\u7684\u518d\u51cf\u53bb\u672c\u8eab\u7684\uff0c\u56e0\u4e3a\u662f\u5927\u4e8e\uff0c\u518d\u52a01\n        }\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>solution \u9898\u76ee\u5927\u610f\uff0c\u8fd9\u9053\u9898\u7684\u610f\u601d\u662f\u80cc\u5305\u5927\u5c0f\u662fm,\u6709n\u4ef6\u7269\u54c1\uff0c\u6700\u4f18\u53d6\u7684\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u53bb\u6389\u8fd9\u4ef6\u7269\u54c1\uff0c\u80fd\u4ea7\u751f\u7684\u6700\u5927\u4ef7\u503c\u4e0e\u4e0d\u53bb\u6389\u65f6\u5019\u7684\u4ef7\u503c\u5dee\u591a\u5c11\u3002 \u9996\u5148\u4f7f\u752801\u80cc\u5305\u628a\u6700\u4f18\u60c5\u51b5\u7b97\u51fa\u6765\uff0c\u7136\u540e\u53bb\u6389\u7b2ci\u4ef6\u7269\u54c1\uff0c\u770b\u770b\u5dee\u503c\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 \\ ios_base::sync_with_stdio(0); \\ cin.tie(0); \\ cout.tie(0); typedef long long ll; typedef pair&lt;int, int&gt; PII; typedef unsigned [&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,14],"class_list":["post-34","post","type-post","status-publish","format-standard","hentry","category-solution","tag-18","tag-14"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/34","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=34"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}