{"id":609,"date":"2020-05-27T18:25:57","date_gmt":"2020-05-27T10:25:57","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=609"},"modified":"2020-05-29T18:23:34","modified_gmt":"2020-05-29T10:23:34","slug":"2020-5","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/05\/27\/2020-5\/","title":{"rendered":"2020 -5"},"content":{"rendered":"<h4>5-27 <a href=\"https:\/\/ac.nowcoder.com\/acm\/problem\/21228\">\u8d27\u5e01\u7cfb\u7edf<\/a><\/h4>\n<p>\u9898\u9762\u770b\u9898\u3002<br \/>\n\u5b8c\u5168\u80cc\u5305\u95ee\u9898\u3002\u5bf9\u539f\u8d27\u5e01\u9762\u989d\u4ece\u5c0f\u5230\u5927\u6392\u4e2a\u5e8f\u3002dp[j]\u8868\u793a\u5728\u5df2\u9009\u7684\u8d27\u5e01\u9762\u989d\u79cd\u7c7b\u4e2d\uff0c\u80fd\u5426\u8868\u793a\u51faj\u3002\u90a3\u4e48\u626b\u63cf\u6570\u7ec4a\uff0c\u5bf9\u4e8ea[i]\uff0c\u82e5dp[a[i]] = true\uff0c\u5373\u80fd\u8868\u793a\u51fa\uff0c\u90a3\u81ea\u7136\u8be5\u8d27\u5e01\u5c31\u53ef\u4ee5\u8df3\u8fc7\u4e86\uff1b\u5426\u5219\u52a0\u5165\u8be5\u8d27\u5e01\uff0cm++\uff0c\u540c\u65f6\u66f4\u65b0\u4e00\u4e0bdp\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\nint n, m, maxx;\nint a[105];\nbool dp[250];\nint main(){\n    int t;\n    scanf (&quot;%d&quot;, &amp;t);\n    while (t--){\n        m = 0;\n        memset (dp, 0, sizeof dp);\n        scanf (&quot;%d&quot;, &amp;n);\n        for (int i=1;i&lt;=n;i++)  scanf (&quot;%d&quot;, a+i);\n        sort (a+1, a+n+1);\n        dp[0] = true;\n        for (int i=1;i&lt;=n;i++){\n            if (!dp[a[i]]){\n                m++;\n                for (int j=a[i];j&lt;=a[n];j++)\n                    dp[j] |= dp[j-a[i]];\n            }\n        }\n        printf (&quot;%d\\n&quot;, m);\n    }\n    return 0;\n}<\/code><\/pre>\n<h4>5-28 <a href=\"https:\/\/ac.nowcoder.com\/acm\/problem\/25043\">Protecting the Flowers<\/a><\/h4>\n<p>\u9898\u610f\uff1a\u6709n\u5934\u725b\u5728\u5403\u53ef\u7231\u7684\u82b1\u6735\uff0c\u73b0\u8981\u628a\u8fd9\u4e9b\u725b\u4e00\u5934\u4e00\u5934\u7684\u8fc1\u56de\u725b\u68da\u53bb\uff0c\u76ee\u7684\u662f\u4f7f\u5403\u7684\u82b1\u6735\u6570\u91cf\u6700\u5c11\u3002\u6bcf\u6b21\u53ea\u80fd\u7275\u4e00\u5934\u725b\uff0c\u4e14\u7275\u8fd9\u5934\u725b\u7684\u540c\u65f6\uff0c\u5176\u5b83\u7684\u725b\u4e5f\u5728\u5403\u82b1\u3002\u6bcf\u5934\u725b\u6709\u4e24\u4e2a\u53c2\u6570\uff1at, d\u3002t\u662f\u628a\u8fd9\u5934\u725b\u7275\u56de\u5230\u725b\u68da\u7684\u65f6\u95f4\uff0cd\u662f\u8fd9\u5934\u725b\u5355\u4f4d\u65f6\u95f4\u5185\u5403\u7684\u82b1\u6735\u6570\u91cf\u3002<br \/>\n(\u6ce8\u610f\u628a\u4e00\u5934\u725b\u7275\u56de\u725b\u68da\u7684\u65f6\u95f4\u4e3at\uff0c\u518d\u4ece\u725b\u68da\u56de\u6765\u8fd8\u9700\u8981t\u65f6\u95f4)<br \/>\n\u8f93\u5165n\uff0c\u7136\u540e\u6bcf\u884c\u4e3at\uff0cd\u3002\u8f93\u51fa\u88ab\u5403\u82b1\u6735\u6570\u91cf\u7684\u6700\u5c0f\u503c\u3002<\/p>\n<p>\u5178\u578b\u7684\u8d2a\u5fc3\uff1a\u6211\u4eec\u5148\u8003\u8651\u53ea\u6709\u4e24\u5934\u725b\u65f6\uff0c\u5148\u7275\u7b2c\u4e00\u5934\u725b\u7684\u4ee3\u4ef7\u662f<strong>2*t1*d2<\/strong>\uff0c\u5148\u7275\u7b2c\u4e8c\u5934\u725b\u7684\u4ee3\u4ef7\u662f<strong>2*t2*d1<\/strong>\u3002\u90a3\u4e48\u8981\u5148\u7275\u90a3\u4e00\u5934\u56de\u53bb\u5462\uff1f\u4f7f\u5f97\u524d\u8005\u7684\u89e3\u4f18\u4e0e\u540e\u8005\u7684\u6761\u4ef6\u662f\uff1a<strong>t1*d2 &lt; t2*d1<\/strong>.<br \/>\n\u5df2\u7ecf\u660e\u4e86\uff0c\u90a3\u4e48\u6839\u636e\u8fd9\u4e2a\u6761\u4ef6\u6765sort\u4e00\u4e0b\uff0c\u7edf\u8ba1\u7b54\u6848\u5373\u53ef\uff01<br \/>\n\u7275\u725b\u7684\u987a\u5e8f\u5c31\u662f 1-&gt;n<\/p>\n<pre><code class=\"language-c++\">#include &lt;bits\/stdc++.h&gt;\nusing namespace std;\ntypedef long long ll;\nconst int maxn = 1e5+5;\nstruct node{\n    ll t, d;\n}a[maxn];\nint n;\nbool cmp(node a, node b){\n    return a.t*b.d &lt; a.d*b.t;\n}\nint main(){\n    ll ans = 0, sum = 0;\n    scanf (&quot;%d&quot;, &amp;n);\n    for (int i=1;i&lt;=n;i++){\n        scanf (&quot;%lld %lld&quot;, &amp;a[i].t, &amp;a[i].d);\n    }\n    sort (a+1, a+n+1, cmp);\n    for (int i=n;i&gt;=1;i--){\n        ans += 2 * a[i].t * sum;\n        sum += a[i].d;\n    }\n    printf (&quot;%lld&quot;, ans);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>5-27 \u8d27\u5e01\u7cfb\u7edf \u9898\u9762\u770b\u9898\u3002 \u5b8c\u5168\u80cc\u5305\u95ee\u9898\u3002\u5bf9\u539f\u8d27\u5e01\u9762\u989d\u4ece\u5c0f\u5230\u5927\u6392\u4e2a\u5e8f\u3002dp[j]\u8868\u793a\u5728\u5df2\u9009\u7684\u8d27\u5e01 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[46],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/609"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=609"}],"version-history":[{"count":4,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/609\/revisions"}],"predecessor-version":[{"id":613,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/609\/revisions\/613"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=609"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}