{"id":370,"date":"2011-08-05T14:54:00","date_gmt":"2011-08-05T06:54:00","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=370"},"modified":"2020-06-06T14:55:06","modified_gmt":"2020-06-06T06:55:06","slug":"%e6%95%b0%e5%ad%97%e4%b8%89%e8%a7%92%e5%bd%a2-%e5%be%aa%e7%8e%af%e7%ae%97%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=370","title":{"rendered":"\u6570\u5b57\u4e09\u89d2\u5f62 \u5faa\u73af\u7b97\u6cd5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n \u5178\u578b\u7684\u52a8\u6001\u89c4\u5212\u601d\u60f3\n \u4ece\u9876\u5c42\u5230\u5e95\u5c42\u586b\u8868\u6bcf\u6b21\u7528\u5230\u4e86\u4e0a\u4e00\u6b21\u7684\u6700\u4f18\u89e3\n \u8df3\u51fa\u540e\u5728\u6700\u540e\u4e00\u884c\u67e5\u627e\u6700\u5927\u7684\u6570\u5373\u53ef \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];\n\nint maxsum(int n)\n{\n\tint i, j;\n\topt&#91;0]&#91;0] = a&#91;0]&#91;0];\n\tfor (i = 1; i &lt; n; i++)\n\t{\n\t\topt&#91;i]&#91;0] = opt&#91;i - 1]&#91;0] + a&#91;i]&#91;0];\n\t\tfor (j = 1; j &lt; i; j++)\n\t\t\tif (a&#91;i]&#91;j] + opt&#91;i - 1]&#91;j] >= a&#91;i]&#91;j] + opt&#91;i - 1]&#91;j - 1])\n\t\t\t\topt&#91;i]&#91;j] = a&#91;i]&#91;j] + opt&#91;i - 1]&#91;j];\n\t\t\telse\n\t\t\t\topt&#91;i]&#91;j] = a&#91;i]&#91;j] + opt&#91;i - 1]&#91;j - 1];\n\t\topt&#91;i]&#91;i] = opt&#91;i - 1]&#91;i - 1] + a&#91;i]&#91;i];\n\t}\n}\n\nint main()\n{\n\n#ifdef LOCAL\n\tfreopen(\"input.txt\", \"r\", stdin);\n\tfreopen(\"output.txt\", \"w\", stdout);\n#endif\n\n\tint i, j, t, 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\tmaxsum(n);\n\t\t\/\/\n\t\tfor (i = 0; i &lt; n; i++)\n\t\t{\n\t\t\tfor (j = 0; j &lt;= i; j++)\n\t\t\t\tcout &lt;&lt; opt&#91;i]&#91;j] &lt;&lt; \" \";\n\t\t\tcout &lt;&lt; endl;\n\t\t}\n\t\t\/\/\n\t\tt = 0;\n\t\tfor (i = 0; i &lt; n; i++)\n\t\t\tif (t &lt; opt&#91;n - 1]&#91;i])\n\t\t\t\tt = opt&#91;n - 1]&#91;i];  \/\/\u67e5\u627e\u6700\u540e\u4e00\u884c\u7684\u6700\u5c0f\u503c \n\t\tcout &lt;&lt; t;\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-370","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\/370","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=370"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/370\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}