{"id":2361,"date":"2025-01-05T11:41:09","date_gmt":"2025-01-05T03:41:09","guid":{"rendered":"https:\/\/guapicoding.com\/?p=2361"},"modified":"2025-03-10T22:27:59","modified_gmt":"2025-03-10T14:27:59","slug":"%e7%ac%94%e8%af%95%e9%a2%98%e8%ae%b0%ef%bc%9a23%e5%b9%b4%e7%bd%91%e6%98%93%e7%a7%8b%e6%8b%9b","status":"publish","type":"post","link":"https:\/\/guapicoding.com\/?p=2361","title":{"rendered":"\u7b14\u8bd5\u9898\u8bb0\uff1a23\u5e74\u7f51\u6613\u79cb\u62db"},"content":{"rendered":"\n<p class=\"has-text-align-left\"><em>link<\/em>\uff1a<a href=\"https:\/\/kamacoder.com\/contest.php?cid=1062\">\u6a21\u62df\u7b14\u8bd5 &#8211; \u5361\u7801\u7f51\u5468\u8d5b\u7b2c\u4e09\u5341\u516d\u671f<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/kamacoder.com\/problempage.php?pid=1253\">175. \u9634\u9633\u5e08<\/a>\u2705<\/h2>\n\n\n\n<p>\u7b80\u5355\u6a21\u62df \u6ce8\u610f\u5411\u4e0a\u53d6\u6574\u6280\u5de7<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nint main() {\n    int n; \n    cin &gt;&gt; n; \n    \n    int a, b;\n    while(n--) {\n        cin &gt;&gt; a &gt;&gt; b;\n        cout &lt;&lt; (a + b - 1) \/ b &lt;&lt; endl; \/\/\u5b9e\u73b0\u5411\u4e0a\u53d6\u6574\n    }\n    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/kamacoder.com\/problempage.php?pid=1254\">176. \u5207\u5272\u6b63\u6570<\/a>\u274c<\/h2>\n\n\n\n<p><em><strong>\u8d85\u65f6\uff1a<\/strong><\/em><strong style=\"font-style: italic;\">\u56de\u6eaf\u6df1\u641c \u628aint\u8f6c\u6362\u4e3astring\u597d\u5207\u5272\u4e00\u4e9b<\/strong><\/p>\n\n\n\n<p><strong><em>\u4e00\u822c\u6df1\u641c\u8d85\u65f6\u7684\u9898\u76ee\u5c31\u5f97\u7528DP\u4e86<\/em><\/strong>  <em><strong>dp[i]\u8868\u793a\u4ee5\u4e0b\u6807 i-1\u4e3a\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u5bf9\u5e94\u7684\u6700\u5927\u548c<\/strong><\/em><strong><em>\uff0c\u5373\u524di\u4e2a\u6570<\/em><\/strong><\/p>\n\n\n\n<p><strong><em>\u6ce8\u610f\u8981\u5355\u72ec\u8ba8\u8bba\u6070\u597d\u4e3a100\u7684\u60c5\u51b5\uff0c\u5c31\u662f\u5728\u8fd9\u91cc\u9519\u4e86<\/em><\/strong><\/p>\n\n\n\n<p><strong>\u56de\u6eaf\u6df1\u641c\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nint res, sum;\nstring x;\n\nvoid backTracking(int index) {\n    if(index &gt;= x.size()) {\n        \/\/ cout &lt;&lt; sum &lt;&lt; endl;\n        res = max(res, sum);\n        return ;\n    }\n    \/\/\u5207\u4e00\u4f4d\u6570\u6216\u4e24\u4f4d\u6570\n    int number&#91;3];\n    number&#91;1] = x&#91;index] - '0';\n    number&#91;2] = x&#91;index + 1] - '0' + 10 * number&#91;1];\n    for(int i = 1; i &lt; 3; i++) {\n        sum += number&#91;i];\n        backTracking(index + i);\n        sum -= number&#91;i];\n    }\n}\nint main() {\n    cin &gt;&gt; x;\n    \n    backTracking(0);\n    \n    cout &lt;&lt; res;\n    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<p><strong>DP\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;bits\/stdc++.h&gt;\nusing namespace std;\n\nint main() {\n    string x;\n    cin &gt;&gt; x;\n    \/\/dp&#91;i]\u8868\u793a\u4ee5\u4e0b\u6807i-1\u7ed3\u5c3e\u7684\u6574\u6570\u7684\u6700\u5927\u5207\u5272\u548c\uff0c\u5373\u524di\u4e2a\u6570\n    vector&lt;int&gt; dp(x.size() + 1, 0);\n    dp&#91;1] = stoi(x.substr(0, 1));\n    dp&#91;2] = stoi(x.substr(0, 2)); \/\/\u80af\u5b9a\u6bd4\u4e24\u4e2a\u6570\u5206\u522b\u52a0\u8d77\u6765\u8981\u5927\n    \n    for(int i = 3; i &lt;= x.size(); i++) {\n        if(stoi(x.substr(i-3, 3)) == 100) dp&#91;i] = dp&#91;i-3] + 100;\n        else dp&#91;i] = max(dp&#91;i-1] + stoi(x.substr(i-1, 1)), dp&#91;i-2] + stoi(x.substr(i-2, 2)));\n    }\n    \n    cout &lt;&lt; dp&#91;x.size()];\n    \n    return 0;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/kamacoder.com\/problempage.php?pid=1255\">177. \u5b66\u4e60\u8bed\u8a00<\/a>\u274c<\/h2>\n\n\n\n<p><strong><em>\u5e76\u67e5\u96c6 \u8d85\u65f6<\/em><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/kamacoder.com\/problempage.php?pid=1256\">178. \u5bfb\u627e\u5e73\u5747\u6570<\/a><\/h2>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>link\uff1a\u6a21\u62df\u7b14\u8bd5 &#8211; \u5361\u7801\u7f51\u5468\u8d5b\u7b2c\u4e09\u5341\u516d\u671f 175. \u9634\u9633\u5e08\u2705 \u7b80\u5355\u6a21\u62df \u6ce8\u610f\u5411\u4e0a\u53d6\u6574\u6280\u5de7 17 [&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":[27,82,81],"class_list":["post-2361","post","type-post","status-publish","format-standard","hentry","category-suanfa","tag-c","tag-82","tag-81"],"_links":{"self":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2361"}],"version-history":[{"count":8,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2361\/revisions"}],"predecessor-version":[{"id":2730,"href":"https:\/\/guapicoding.com\/index.php?rest_route=\/wp\/v2\/posts\/2361\/revisions\/2730"}],"wp:attachment":[{"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guapicoding.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}