{"id":245,"date":"2023-06-25T17:51:34","date_gmt":"2023-06-25T09:51:34","guid":{"rendered":"https:\/\/solost.cn\/?p=245"},"modified":"2023-06-25T17:51:34","modified_gmt":"2023-06-25T09:51:34","slug":"373","status":"publish","type":"post","link":"https:\/\/solost.cn\/?p=245","title":{"rendered":"AtCoder Beginner Contest 306 &#8211; D &#8211; Poisonous Full-Course"},"content":{"rendered":"<h2>\u9898\u76ee\u8fde\u63a5<\/h2>\n<p><a href=\"https:\/\/atcoder.jp\/contests\/abc306\/tasks\/abc306_d\">\u94fe\u63a5<\/a><\/p>\n<h2>\u9898\u76ee\u5927\u610f<\/h2>\n<p>\u6709N\u4e2a\u7269\u54c1\uff0c0\u7269\u54c1\u65e0\u6bd2\uff0c1\u7269\u54c1\u6709\u6bd2\uff0c\u4f60\u4e0d\u80fd\u8fde\u7eed\u5403\u4e24\u6b21\u6709\u6bd2\u7684\u4e1c\u897f\uff0c\u5403\u5b8c\u6ca1\u6bd2\u7684\u5c31\u4f1a\u4ece\u524d\u4e00\u79cd\u72b6\u6001\u8f6c\u79fb\u5230\u73b0\u5728\u5403\u7684\u4e1c\u897f\u7684\u72b6\u6001\uff0c\u95ee\u4f60\u5403\u4e86\u7684\u4e1c\u897f\u7684\u603b\u4ef7\u503c\u662f\u591a\u5c11\u3002<\/p>\n<h2>\u9898\u89e3<\/h2>\n<p>\u521a\u5f00\u59cb\u60f3\u7684\u662f\u53cc\u6307\u9488\u626b\u63cf\uff0c\u4f46\u662f\u4f1a\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5982\u679c\u524d\u9762\u9009\u7684\u662f0\uff0c\u73b0\u5728\u9009\u4e86\u4e00\u4e2a1\uff0c\u53ef\u80fd\u540e\u9762\u53ea\u6709\u4e00\u4e2a0\uff0c\u5bfc\u81f4\u4f60\u9009\u4e8610\u8fd9\u79cd\u60c5\u51b5\u53cd\u800c\u4f1a\u4f7f\u4ef7\u503c\u51cf\u5c11\uff0c\u6240\u4ee5\u6392\u9664\u53cc\u6307\u9488\u8fd9\u79cd\u5199\u6cd5\u3002\u6539\u4e3adp<\/p>\n<ul>\n<li><code>x[i] == 1, f[i][0] = f[i - 1][0], f[i][1] = max(f[i - 1][0] + y, f[i - 1][1]<\/code><\/li>\n<li><code>x[i] == 0, f[i][0] = max(f[i - 1][0], f[i - 1][1] + y,f[i - 1][0] + y, f[i][1] = f[i - 1][1] <\/code><\/li>\n<\/ul>\n<h2>\u4ee3\u7801<\/h2>\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;unordered_set&gt;\n#include &lt;vector&gt;\n\n#define x first\n#define y second\n#define endl &#039;\\n&#039;\n#define IOS                       \\\n    ios_base::sync_with_stdio(0); \\\n    cin.tie(0);                   \\\n    cout.tie(0);\n\nusing namespace std;\n\ntypedef long long ll;\ntypedef pair&lt;ll, ll&gt; pll;\ntypedef pair&lt;int, int&gt; pii;\ntypedef unsigned long long ull;\n\nconst int INF = 0x3f3f3f3f, mod = 1000000007;\nconst int N = 3e5 + 10;\nll f[N][2];\npll a[N];\nvoid solve()\n{\n    int n;\n    cin &gt;&gt; n;\n    ll sum = 0, p = 0;\n    for (int i = 1; i &lt;= n; i++) {\n        cin &gt;&gt; a[i].x &gt;&gt; a[i].y;\n    }\n    for (int i = 1; i &lt;= n; i++) {\n        ll &amp;x = a[i].x, &amp;y = a[i].y;\n        if(x == 1){\n            f[i][0] = f[i - 1][0];\n            f[i][1] = max(f[i - 1][1], f[i - 1][0] + y);\n        }\n        else{\n            f[i][0] = max(f[i - 1][0], max(f[i - 1][0] + y, f[i - 1][1] + y));\n            f[i][1] = f[i - 1][1];\n        }\n    }\n    cout &lt;&lt; max(f[n][0], f[n][1]) &lt;&lt; endl;\n}\nint main()\n{\n    \/\/ IOS;\n    int t = 1;\n    \/\/ cin &gt;&gt; t;\n    while (t--) {\n        solve();\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u8fde\u63a5 \u94fe\u63a5 \u9898\u76ee\u5927\u610f \u6709N\u4e2a\u7269\u54c1\uff0c0\u7269\u54c1\u65e0\u6bd2\uff0c1\u7269\u54c1\u6709\u6bd2\uff0c\u4f60\u4e0d\u80fd\u8fde\u7eed\u5403\u4e24\u6b21\u6709\u6bd2\u7684\u4e1c\u897f\uff0c\u5403\u5b8c\u6ca1\u6bd2\u7684\u5c31\u4f1a\u4ece\u524d\u4e00\u79cd\u72b6\u6001\u8f6c\u79fb\u5230\u73b0\u5728\u5403\u7684\u4e1c\u897f\u7684\u72b6\u6001\uff0c\u95ee\u4f60\u5403\u4e86\u7684\u4e1c\u897f\u7684\u603b\u4ef7\u503c\u662f\u591a\u5c11\u3002 \u9898\u89e3 \u521a\u5f00\u59cb\u60f3\u7684\u662f\u53cc\u6307\u9488\u626b\u63cf\uff0c\u4f46\u662f\u4f1a\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5982\u679c\u524d\u9762\u9009\u7684\u662f0\uff0c\u73b0\u5728\u9009\u4e86\u4e00\u4e2a1\uff0c\u53ef\u80fd\u540e\u9762\u53ea\u6709\u4e00\u4e2a0\uff0c\u5bfc\u81f4\u4f60\u9009\u4e8610\u8fd9\u79cd\u60c5\u51b5\u53cd\u800c\u4f1a\u4f7f\u4ef7\u503c\u51cf\u5c11\uff0c\u6240\u4ee5\u6392\u9664\u53cc\u6307\u9488\u8fd9\u79cd\u5199\u6cd5\u3002\u6539\u4e3adp x[i] == 1, f[i][0] = f[i - 1][0], f[i][1] = max(f[i - 1][0] + y, f[i - 1][1] x[i] == 0, f[i][0] = max(f[i - 1][0], f[i - 1][1] + y,f[i - 1][0] + y, f[i][1] = f[i - 1][1] \u4ee3\u7801 #include &lt;algorithm&gt; #include &lt;bitset&gt; #include &lt;cmath&gt; #include &lt;cstdio&gt; [&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":[40,18],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-solution","tag-dp","tag-18"],"_links":{"self":[{"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/245","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=245"}],"version-history":[{"count":0,"href":"https:\/\/solost.cn\/index.php?rest_route=\/wp\/v2\/posts\/245\/revisions"}],"wp:attachment":[{"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solost.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}