{"id":657,"date":"2020-03-09T23:59:41","date_gmt":"2020-03-09T15:59:41","guid":{"rendered":"http:\/\/kylelv.com\/?p=657"},"modified":"2020-03-11T10:05:54","modified_gmt":"2020-03-11T02:05:54","slug":"pdl%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/blog.kylelv.com\/?p=657","title":{"rendered":"PDL\u5b66\u4e60"},"content":{"rendered":"\n<p>PDL (Problem Description Language)\u662f\u4e00\u79cd\u7528\u4e8e\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u5efa\u6a21\u7684\u8bed\u8a00\u3002<\/p>\n\n\n\n<div class=\"wp-block-file\"><a href=\"http:\/\/kylelv.com\/wp-content\/uploads\/2020\/03\/PDL.pdf\" target=\"_blank\" rel=\"noopener\">PDL\u4f7f\u7528\u624b\u518c<\/a><a href=\"http:\/\/kylelv.com\/wp-content\/uploads\/2020\/03\/PDL.pdf\" class=\"wp-block-file__button\" download target=\"_blank\" rel=\"noopener\">\u4e0b\u8f7d<\/a><\/div>\n\n\n\n<p><s>\u7b80\u7b54\u6d4b\u8bc4\uff1f<\/s>\u7528\u6237\u4f53\u9a8c\uff08\u96fe<br>\u5927\u4f53\u611f\u89c9\u4e3b\u8981\u7528\u4e8e\u641c\u7d22\u95ee\u9898\u7684\u6c42\u89e3\uff0c\u6a21\u62df\u4e86\u4eba\u7684\u601d\u8003\u6a21\u5f0f\uff0c\u5c06\u9700\u6c42\u548c\u9650\u5b9a\u5199\u51fa\uff0c\u53ef\u4ee5\u7531\u7b80\u5355\u51e0\u884c\u4ee3\u7801\u5b9e\u73b0\u9700\u6c42\uff0c\u81ea\u52a8\u751f\u6210\u53ef\u884c\u7684\u6c42\u89e3\u7b97\u6cd5\u53ca\u76f8\u5e94\u7684\u6e90\u4ee3\u7801<br>\u53ef\u4ee5\u53d1\u73b0\u5176\u5bf9\u4e8e\u7b97\u6cd5\u5339\u914d\u8f83\u4e3a\u7cbe\u51c6\uff0c\u590d\u6742\u5ea6\u8f83\u4f4e\uff0c\u4f46\u96be\u4ee5\u505a\u5230\u6700\u4f18\u590d\u6742\u5ea6\uff0c\u4e14\u76ee\u524d\u6765\u770b\u6bd4\u8f83\u5bb9\u6613\u5b9e\u73b0\u8f83\u7b80\u5355\u7684\u7b97\u6cd5\uff0c\u800c\u66f4\u9ad8\u7ea7\u7684\u7b97\u6cd5\u6216\u5d4c\u5957\u96be\u4ee5\u5b9e\u73b0\u6216\u8868\u8fbe\uff0c\u4ecd\u6709\u5f88\u5927\u4e0a\u5347\u7a7a\u95f4<br>\u53ef\u80fd\u56e0\u4e3aPDL\u548c\u5e38\u89c4\u7b97\u6cd5\u5bf9\u4e8e\u95ee\u9898\u5b9e\u73b0\u601d\u8def\u4e0d\u4e00\u81f4\uff0c\u521d\u6b21\u63a5\u89e6\u4e0a\u624b\u8f83\u96be\uff0c\u4f46\u719f\u6089\u4e4b\u540e\uff0c\u5e94\u8be5\u4f1a\u5bf9\u90e8\u5206\u641c\u7d22\u95ee\u9898\u7684\u5b9e\u73b0\u8d77\u5230\u5f88\u5927\u7684\u5e2e\u52a9\uff0c\u6216\u8bb8\u5c06\u4f1a\u6781\u5927\u7684\u51cf\u5c0f\u4ee3\u7801\u5b9e\u73b0\u7684\u96be\u5ea6\u548c\u4ee3\u7801\u5de5\u7a0b\u91cf<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">A:\u627e\u76f8\u540c\u6570<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:&nbsp;1000ms&nbsp;\u5185\u5b58\u9650\u5236:&nbsp;65536kB<\/p>\n\n\n\n<p class=\"has-text-align-left\">\u63cf\u8ff0<\/p>\n\n\n\n<p>\u5728\u957f\u5ea6\u4e3an\uff081&lt;=n&lt;=1000\uff09\u7684\u6574\u6570\uff08\u6bcf\u4e2a\u6574\u6570\u57280~10000\u4e4b\u95f4\uff09\u5e8f\u5217\u4e2d\uff0c\u627e\u5230\u51fa\u73b0\u4e86\u4e24\u6b21\u7684\u6570\u3002<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u8f93\u5165\u4e00\u4e2a\u6574\u6570n<br>\u7b2c\u4e8c\u884c\u8f93\u5165\u5e8f\u5217\uff0c\u7528\u7a7a\u683c\u5206\u5f00<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u51fa\u73b0\u4e86\u4e24\u6b21\u7684\u6570\uff0c\u4fdd\u8bc1\u5b58\u5728\u4e14\u552f\u4e00<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4\n1 2 4 2<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">2<\/pre>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u5e38\u89c4\u505a\u6cd5\u53ef\u80fd\u91cd\u5728\u50a8\u5b58\u4fe1\u606f\u6765\u51cf\u5c0f\u590d\u6742\u5ea6<br>\u800cPDL\u5219\u57fa\u4e8e\u7684\u662f\u641c\u7d22\u7684\u601d\u60f3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#input\n    N of int in [1,1000];\n    a of (int in [0,10000]) [1~N];\n#required\n    i of int in [1,N];\n    j of int in [1,N];\n    a[i]=a[j] and i&lt;j;\n#output\n    a[i];<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">B:\u65c5\u884c\u5546\u95ee\u9898<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:&nbsp;1000ms&nbsp;\u5185\u5b58\u9650\u5236:&nbsp;65536kB<\/p>\n\n\n\n<p class=\"has-text-align-left\">\u63cf\u8ff0<\/p>\n\n\n\n<p>\u67d0\u56fd\u5bb6\u6709n\uff081&lt;=n&lt;=10\uff09\u5ea7\u57ce\u5e02\uff0c\u7ed9\u5b9a\u4efb\u610f\u4e24\u5ea7\u57ce\u5e02\u95f4\u8ddd\u79bb\uff08\u4e0d\u8d85\u8fc71000\u7684\u975e\u8d1f\u6574\u6570\uff09\u3002\u4e00\u4e2a\u65c5\u884c\u5546\u4eba\u5e0c\u671b\u8bbf\u95ee\u6bcf\u5ea7\u57ce\u5e02\u6070\u597d\u4e00\u6b21\uff08\u51fa\u53d1\u5730\u4efb\u9009\uff0c\u4e14\u6700\u7ec8\u65e0\u9700\u8fd4\u56de\u51fa\u53d1\u5730\uff09\u3002\u6c42\u6700\u77ed\u7684\u8def\u5f84\u957f\u5ea6\u3002<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u8f93\u5165\u4e00\u4e2a\u6574\u6570n<br>\u63a5\u4e0b\u6765n\u884c\uff0c\u6bcf\u884cn\u4e2a\u6570\uff0c\u7528\u7a7a\u683c\u9694\u5f00\uff0c\u4ee5\u90bb\u63a5\u77e9\u9635\u5f62\u5f0f\u7ed9\u51fa\u57ce\u5e02\u95f4\u8ddd\u79bb\u3002\u8be5\u90bb\u63a5\u77e9\u9635\u662f\u5bf9\u79f0\u7684\uff0c\u4e14\u5bf9\u89d2\u7ebf\u4e0a\u5168\u4e3a0<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u4e00\u884c\uff0c\u6700\u77ed\u8def\u5f84\u7684\u957f\u5ea6<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">6\n0 16 1 10 12 15\n16 0 10 2 10 8\n1 10 0 10 5 10\n10 2 10 0 9 3\n12 10 5 9 0 8\n15 8 10 3 8 0<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">19<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#input \n    n of int in [1,10];\n    lj of (int in [0 ,1000])[1~n][1~n];\n#required\n    a of (int in[1,n])[1~n];\n    alldiff a;\n#objective\n    minimize summation [lj[a[i]][a[i+1]] : forall i (i of int in [1,n-1])];<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"has-text-align-center wp-block-heading\">C:\u56e2\u961f\u5408\u4f5c<\/h2>\n\n\n\n<p class=\"has-text-align-center\">\u603b\u65f6\u95f4\u9650\u5236:&nbsp;1000ms&nbsp;\u5185\u5b58\u9650\u5236:&nbsp;65536kB<\/p>\n\n\n\n<p>\u63cf\u8ff0<\/p>\n\n\n\n<p>\u4f60\u9700\u8981\u6311\u9009\u82e5\u5e72\u6210\u5458\u7ec4\u5efa\u4e00\u4e2a\u5de5\u4f5c\u56e2\u961f\u3002\u73b0\u6709n\uff081&lt;=n&lt;=100\uff09\u540d\u5019\u9009\u4eba\uff0c\u6bcf\u4e2a\u4eba\u6709\u4e00\u4e2a\u201c\u51dd\u805a\u529b\u201d\u548c\u4e00\u4e2a\u201c\u5de5\u4f5c\u80fd\u529b\u201d\uff08\u5747\u4e3a-50\u81f350\u7684\u6574\u6570\uff09\u3002\u8981\u786e\u4fdd\u56e2\u961f\u80fd\u591f\u987a\u5229\u5408\u4f5c\uff0c\u6240\u6709\u6210\u5458\u7684\u201c\u51dd\u805a\u529b\u201d\u4e4b\u548c\u5fc5\u987b\u4e3a\u6b63\u3002\u5728\u8fd9\u4e2a\u6761\u4ef6\u4e0b\uff0c\u56e2\u961f\u7684\u603b\u201c\u5de5\u4f5c\u80fd\u529b\u201d\u6700\u5927\u662f\u591a\u5c11\uff1f\u4fdd\u8bc1\u81f3\u5c11\u5b58\u5728\u4e00\u4e2a\u6ee1\u8db3\u6761\u4ef6\u4e14\u603b\u201c\u5de5\u4f5c\u80fd\u529b\u201d\u4e3a\u6b63\u7684\u56e2\u961f\u3002<\/p>\n\n\n\n<p>\u8f93\u5165<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u8f93\u5165\u4e00\u4e2a\u6574\u6570n<br>\u7b2c\u4e8c\u884c\u8f93\u5165n\u4e2a\u6574\u6570\uff0c\u7528\u7a7a\u683c\u9694\u5f00\uff0c\u4f9d\u6b21\u4e3a\u5404\u5019\u9009\u4eba\u7684\u51dd\u805a\u529b<br>\u7b2c\u4e09\u884c\u8f93\u5165n\u4e2a\u6574\u6570\uff0c\u7528\u7a7a\u683c\u9694\u5f00\uff0c\u4f9d\u6b21\u4e3a\u5404\u5019\u9009\u4eba\u7684\u5de5\u4f5c\u80fd\u529b<\/p>\n\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>\u4e00\u4e2a\u6574\u6570\uff0c\u6700\u5927\u7684\u56e2\u961f\u603b\u201c\u5de5\u4f5c\u80fd\u529b\u201d<\/p>\n\n\n\n<p>\u6837\u4f8b\u8f93\u5165<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">5\n-5 8 6 2 -8\n7 -6 -3 1 -5<\/pre>\n\n\n\n<p>\u6837\u4f8b\u8f93\u51fa<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">5<\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>#input\n    n of int in [1,100];\n    a of (int in [-50,50])[1~n];\n    b of (int in [-50,50])[1~n];\n#required\n    ans of (int in [1,n]) {};\n    summation [a[i] : forall i (i in ans)]>0;\n#objective\n    maximize summation [b[i] : forall i (i in ans)];<\/code><\/pre>\n\n\n\n<p>PDL2CPP Source Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstring>\n#include&lt;cstdlib>\n#include&lt;set>\n\nint n;\nint a[100];\nint b[100];\nint ans[100];\nint _result;\nint _best__result;\n\nvoid _input() {\n\tstd::cin >> n;\n\tfor (int _tmp0 = 1; _tmp0 &lt;= n; _tmp0++)\n\t\tstd::cin >> a[_tmp0 - 1];\n\tfor (int _tmp0 = 1; _tmp0 &lt;= n; _tmp0++)\n\t\tstd::cin >> b[_tmp0 - 1];\n}\n\nvoid _output() {\n\tstd::cout &lt;&lt; _best__result &lt;&lt; std::endl;\n}\n\nvoid _update() {\n\tif (_result &lt;= _best__result)\n\t\treturn;\n\t_best__result = _result;\n}\n\nint _DP_ans[100][5001];\n\nint _find_ans(int _step, int _sum1, int _sum2) {\n\tif (_step == n - 1 + 1) {\n\t\t_result = _sum2;\n\t\tif (!(_sum1 > 0))\n\t\t\treturn -5001;\n\t\t_update();\n\t\treturn _sum2;\n\t}\n\tif (_DP_ans[_step][_sum1] != -5001) {\n\t\t_sum2 += _DP_ans[_step][_sum1];\n\t\t_result = _sum2;\n\t\tif (!(_sum1 > 0))\n\t\t\treturn -5001;\n\t\t_update();\n\t\treturn _sum2;\n\t}\n\tint __sum1 = _sum1;\n\tint __sum2 = _sum2;\n\tfor (ans[_step] = 0; ans[_step] &lt;= 1; ans[_step]++) {\n\t\t_sum1 = __sum1;\n\t\t_sum2 = __sum2;\n\t\tif (ans[_step + 1 - 1])\n\t\t\t_sum1 += a[_step + 1 - 1];\n\t\tif (ans[_step + 1 - 1])\n\t\t\t_sum2 += b[_step + 1 - 1];\n\t\tif (!(_sum1 + 50 * (100 - _step) > 0))\n\t\t\tcontinue;\n\t\tif (!(_sum2 + 50 * (100 - _step) > _best__result))\n\t\t\tcontinue;\n\t\tint _tmp0 = _find_ans(_step + 1, _sum1, _sum2) - __sum2;\n\t\tif (_tmp0 > _DP_ans[_step][__sum1])\n\t\t\t_DP_ans[_step][__sum1] = _tmp0;\n\t}\n\treturn __sum2 + _DP_ans[_step][__sum1];\n}\n\nvoid _solve() {\n\t_best__result = -5001;\n\tfor (int _tmp0 = 0; _tmp0 &lt; 100; _tmp0++)\n\t\tfor (int _tmp1 = 0; _tmp1 &lt; 5001; _tmp1++)\n\t\t\t_DP_ans[_tmp0][_tmp1] = -5001;\n\t_find_ans(0, 0, 0);\n}\n\nint main() {\n\t_input();\n\t_solve();\n\t_output();\n\treturn 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>PDL (Problem Description Language)\u662f\u4e00\u79cd\u7528\u4e8e\u7ec4\u5408\u4f18\u5316\u95ee\u9898\u5efa\u6a21\u7684\u8bed\u8a00\u3002 \u7b80\u7b54\u6d4b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"class_list":["post-657","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=657"}],"version-history":[{"count":2,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions"}],"predecessor-version":[{"id":668,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=\/wp\/v2\/posts\/657\/revisions\/668"}],"wp:attachment":[{"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kylelv.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}