{"id":368,"date":"2011-08-05T14:53:00","date_gmt":"2011-08-05T06:53:00","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=368"},"modified":"2020-06-06T14:54:15","modified_gmt":"2020-06-06T06:54:15","slug":"%e6%95%b0%e5%ad%97%e4%b8%89%e8%a7%92%e5%bd%a2-%e5%8a%a8%e6%80%81%e8%a7%84%e5%88%92","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=368","title":{"rendered":"\u6570\u5b57\u4e09\u89d2\u5f62 \u52a8\u6001\u89c4\u5212"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n \u7528opt&#91;]&#91;]\u6765\u8bb0\u5f55\u5df2\u7ecf\u4ea7\u751f\u7684\u6700\u4f18\u89e3\n \u6765\u89e3\u51b3\u5bf9\u67d0\u4e9b\u6700\u4f18\u89e3\u8fdb\u884c\u91cd\u590d\u6c42\u89e3\u7684\u95ee\u9898 \n *\/\n#define LOCAL\n#include&lt;iostream>\nusing namespace std;\n#define N 100\nint a&#91;N]&#91;N], opt&#91;N]&#91;N];\nint sum(int i, int j, int n)\n{\n\tif (opt&#91;i]&#91;j])\n\t\treturn opt&#91;i]&#91;j] + a&#91;i]&#91;j];\n\telse\n\t{\n\t\tif (i == n - 1)\n\t\t\treturn a&#91;i]&#91;j];\n\t\tif ((opt&#91;i]&#91;j] = sum(i + 1, j, n)) > (opt&#91;i]&#91;j] = sum(i + 1, j + 1, n)))\n\t\t\treturn opt&#91;i]&#91;j] + a&#91;i]&#91;j];\n\t\telse\n\t\t\treturn opt&#91;i]&#91;j] + a&#91;i]&#91;j];\n\t}\n}\nint main()\n{\n#ifdef LOCAL\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tint i, j, n;\n\twhile (cin >> n)\n\t{\n\t\tmemset(opt, 0, sizeof(opt));\n\t\tfor (i = 0; i &lt; n; i++)\n\t\t\tfor (j = 0; j &lt;= i; j++)\n\t\t\t\tcin >> a&#91;i]&#91;j];\n\t\tcout &lt;&lt; sum(0, 0, n) &lt;&lt; endl;\n\t}\n\treturn 0;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-368","post","type-post","status-publish","format-standard","hentry","category-06-03-play-ground"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=368"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/368\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=368"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}