{"id":366,"date":"2020-04-21T17:46:54","date_gmt":"2020-04-21T09:46:54","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=366"},"modified":"2020-04-23T14:45:39","modified_gmt":"2020-04-23T06:45:39","slug":"4-19-%e8%a1%a5%e9%a2%98-%e7%ac%ac%e5%9b%9b%e6%ac%a1%e8%ae%ad%e7%bb%83","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/04\/21\/4-19-%e8%a1%a5%e9%a2%98-%e7%ac%ac%e5%9b%9b%e6%ac%a1%e8%ae%ad%e7%bb%83\/","title":{"rendered":"4-19 \u8865\u9898 \u7b2c\u56db\u6b21\u8bad\u7ec3"},"content":{"rendered":"<h4><a href=\"https:\/\/vjudge.net\/contest\/369109#problem\">A.Dima and Salad<\/a><\/h4>\n<p>\u9898\u610f\uff1a\u6709n\u4e2a\u7269\u4f53\uff0c\u6bcf\u4e2a\u7269\u4f53\u6709\u4e24\u4e2a\u53c2\u6570\uff0ca\uff0cb\uff0c\u8f93\u5165k\uff0c\u4ecen\u4e2a\u7269\u54c1\u4e2d\u9009\u51fa\u82e5\u5e72\u4e2a\uff0c\u8981\u6c42\u5728\u6ee1\u8db3<br \/>\n<code class=\"katex-inline\">\\displaystyle \\sum^{m}_{j=1}{{a[j]}} = k*\\displaystyle \\sum^{m}_{j=1}{{b[j]}}<\/code>\u7684\u57fa\u7840\u4e0a\uff0c\u4f7f\u5f97a[j]\u7684\u548c\u6700\u5927\u3002<br \/>\n\u5bf9\u516c\u5f0f\u53d8\u5f62\uff0c\u4f7f<code class=\"katex-inline\">b[i] = k*b[i]-a[i]<\/code>\uff0c\u95ee\u9898\u8f6c\u53d8\u6210\u4f7fb[i]\u4e4b\u548c\u4e3a0\u7684\u6761\u4ef6\u4e0b\uff0ca[i]\u7684\u548c\u6700\u5927\u3002\u4f46\u662fb[i]\u6709\u6b63\u6709\u8d1f\uff0c\u6240\u4ee5\u7ef4\u62a4\u4e24\u4e2a\u6570\u7ec4f[]\uff0cg[]\uff0cf[i]\u8868\u793a\u6240\u6709\u6b63\u7684b\u4e2d\uff0c\u548c\u4e3ai\u65f6a\u7684\u6700\u5927\u548c\uff0cg[i]\u8868\u793a\u6240\u6709\u8d1f\u7684b\u4e2d\uff0c\u548c\u4e3a-i\u65f6a\u7684\u6700\u5927\u548c\u3002\u6700\u540e\u7edf\u8ba1\u7b54\u6848\u65f6\uff0c\u627e\u5230max(f[i]+g[i])\u5373\u53ef\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;cstdio&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\nconst int maxn = 1e5+5;\nint a[105],b[105];\nint f[maxn+10],g[maxn+10];\nint main(){\n    int n,k,ans = 0;\n    scanf (&quot;%d %d&quot;,&amp;n,&amp;k);\n    for (int i=1;i&lt;=n;i++)\n        scanf (&quot;%d&quot;,&amp;a[i]);\n    for (int i=1;i&lt;=n;i++){\n        scanf (&quot;%d&quot;,&amp;b[i]);\n        b[i] *= k;  b[i] -= a[i];\n    }\n    for (int i=1;i&lt;=n;i++){\n        if (b[i]&gt;0){\n            for (int j=maxn;j&gt;=b[i];j--)    if (f[j-b[i]] || j-b[i]==0)\n                f[j] = max(f[j],f[j-b[i]]+a[i]);\n        }else{\n            for (int j=maxn;j&gt;=-b[i];j--)   if (g[j+b[i]] || j+b[i]==0)\n                g[j] = max(g[j],g[j+b[i]]+a[i]);\n        }\n    }\n    ans = max (ans,f[0]+g[0]);\n    for (int i=1;i&lt;=maxn;i++)\n        ans = max(ans,(f[i]&amp;&amp;g[i])?f[i]+g[i]:0);\n    printf (&quot;%d&quot;,ans?ans:-1);\n    return 0;\n}<\/code><\/pre>\n<h4><a href=\"https:\/\/vjudge.net\/contest\/369109#problem\/H\">H.Palindrome<\/a><\/h4>\n<p>\u9898\u610f\uff1a\u7ed9\u4e00\u5b57\u7b26\u4e32s\uff0c1&lt;=|s|&lt;=5e4\uff0c\u6c42\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u6700\u5927\u56de\u6587\u5b50\u5e8f\u5217\uff0c\u5f53\u5b50\u5e8f\u5217\u957f\u5ea6\u8d85\u8fc7100\u65f6\uff0c\u53ea\u8f93\u51fa100\u4e2a\uff0c\u5426\u5219\u5168\u90e8\u8f93\u51fa\u3002s\u7531\u5c0f\u5199\u5b57\u6bcd\u6784\u6210\u3002<br \/>\n\u8003\u8651\u5230s\u53ea\u6709\u5c0f\u5199\u5b57\u6bcd\uff0c\u4e14\u53ea\u6c42\u957f\u5ea6&lt;=100\u7684\u5b50\u5e8f\u5217\uff0c\u6240\u4ee5\u53ea\u9700\u8003\u8651s\u7684\u524d2600\u4e2a\u5b57\u7b26\u5373\u53ef\u3002\u7136\u540e\u533a\u95f4dp\u6c42\u89e3\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;cstdio&gt;\n#include &lt;algorithm&gt;\n#include &lt;cstring&gt;\nusing namespace std;\nconst int maxn = 5e4+6;\nchar s[maxn];\nchar ans[maxn];\nint tot;\nint dp[2605][2605];\nint main(){\n    scanf (&quot;%s&quot;,s+1);\n    int len = min((int)strlen(s+1),2600);\n    for (int i=1;i&lt;=len;i++)    dp[i][i] = 1;\n    for (int i=1;i&lt;=len;i++)   for (int j=i-1;j&gt;=1;j--){\n        dp[j][i] = max(dp[j][i-1],dp[j+1][i]);\n        if (s[i]==s[j]) dp[j][i] = max(dp[j][i],dp[j+1][i-1]+2);\n    }\n    int begin = 1, end = len;  tot = 0;\n    while (begin&lt;end){\n        if (dp[begin][end]==dp[begin+1][end]){\n            begin++;\n            continue;\n        }else if (dp[begin][end]==dp[begin][end-1]){\n            end--;\n            continue;\n        }else{\n            ans[++tot] = s[end];\n            begin++,end--;\n        }\n    }\n    int lengt = 2*tot+(begin==end);\n    if (lengt&lt;=100){\n        for (int i=1;i&lt;=tot;i++)    putchar(ans[i]);\n        if (begin==end) putchar(s[begin]);\n        for (int j=tot;j&gt;=1;j--)    putchar(ans[j]);\n    }else{\n        for (int i=1;i&lt;=50;i++)    putchar(ans[i]);\n        for (int j=50;j&gt;=1;j--)    putchar(ans[j]);\n    }\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>A.Dima and Salad \u9898\u610f\uff1a\u6709n\u4e2a\u7269\u4f53\uff0c\u6bcf\u4e2a\u7269\u4f53\u6709\u4e24\u4e2a\u53c2\u6570\uff0ca\uff0cb\uff0c\u8f93\u5165k\uff0c\u4ecen\u4e2a\u7269\u54c1\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[27],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/366"}],"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=366"}],"version-history":[{"count":4,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"predecessor-version":[{"id":383,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions\/383"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}