{"id":6983,"date":"2024-07-22T16:01:01","date_gmt":"2024-07-22T08:01:01","guid":{"rendered":""},"modified":"2024-07-22T16:01:01","modified_gmt":"2024-07-22T08:01:01","slug":"\u6700\u5927\u5b50\u6bb5\u548cc++\u4ee3\u7801_c++\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf\u5b58\u653e\u5728\u54ea\u91cc","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6983.html","title":{"rendered":"\u6700\u5927\u5b50\u6bb5\u548cc++\u4ee3\u7801_c++\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf\u5b58\u653e\u5728\u54ea\u91cc"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u7ed9\u5b9a\u7531n\u4e2a\u6574\u6570\uff08\u53ef\u80fd\u4e3a\u8d1f\u6574\u6570\uff09\u7ec4\u6210\u7684\u5e8f\u5217a[1],a[2],a[3],\u2026,a[n],\u6700\u5927\u5b50\u6bb5\u548c\u95ee\u9898<\/strong>\uff08sum of largest sub-segment problem\uff09\u8981\u6c42\u8be5\u5e8f\u5217\u5982a[i]+a[i+1]+\u2026+a[j]\u7684\u6700\u5927\u503c\uff0c\u5f53\u6240\u7ed9\u7684\u6574\u6570\u5747\u4e3a\u8d1f\u6570\u65f6\u5b9a\u4e49\u5b50\u6bb5\u548c\u4e3a0\uff0c\u4f9d\u6b64\u5b9a\u4e49\uff0c\u6240\u6c42\u7684\u6700\u4f18\u503c\u4e3a\uff1aMax{0,a[i]+a[i+1]+\u2026+a[j]},1<=i<=j<=n\u3002\u4f8b\u5982\uff0c\u5f53\uff08a[1],a[2],a[3],a[4],a[5],a[6]\uff09=(-20,11,-4,13,-5,-2)\u65f6\uff0c\u6700\u5927\u5b50\u6bb5\u548c\u4e3a20\u3002
\u5728\u672c\u6587\u4e2d\uff0c\u5c06\u4ecb\u7ecd\u4e24\u79cd\u65b9\u6cd5\uff08\u86ee\u529b\u6cd5\u3001\u52a8\u6001\u89c4\u5212\u6cd5\uff09\u5e76\u5206\u522b\u5206\u6790\u4e24\u79cd\u65b9\u6cd5\u7684\u65f6\u95f4\u6548\u7387\u3002<\/p>\n

\u86ee\u529b\u6cd5<\/h2>\n

\u86ee\u529b\u6cd5\u89e3\u51b3\u672c\u95ee\u9898\u975e\u5e38\u7b80\u5355\u7c97\u66b4\uff0c\u76f4\u63a5\u7528\u5faa\u73af\u5d4c\u5957\uff0c\u6bd4\u8f83\u6240\u6709\u5b50\u6bb5\u548c\u7684\u5927\u5c0f\uff0c\u6700\u540e\u8f93\u51fa\u6700\u5927\u5b50\u6bb5\u548c\u3002<\/p>\n

\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n

#include<\/span><iostream><\/span><\/span> using<\/span> namespace<\/span> std;<\/span> int<\/span> MaxSubsegmentSum1<\/span>(<\/span>int<\/span> n,<\/span>int<\/span> array[<\/span>]<\/span>)<\/span> { \n   <\/span> int<\/span> Max=<\/span>0<\/span>;<\/span> for<\/span>(<\/span>int<\/span> i=<\/span>0<\/span>;<\/span>i<<\/span>n;<\/span>i++<\/span>)<\/span> \/\/\u8d77\u59cb\u4f4d\u7f6e <\/span> { \n   <\/span> for<\/span>(<\/span>int<\/span> j=<\/span>i;<\/span>j<<\/span>n;<\/span>j++<\/span>)<\/span> \/\/\u7ed3\u675f\u4f4d\u7f6e <\/span> { \n   <\/span> int<\/span> sum=<\/span>0<\/span>;<\/span> for<\/span>(<\/span>int<\/span> k=<\/span>i;<\/span>k<=<\/span>j;<\/span>k++<\/span>)<\/span> \/\/\u6c42\u4ecei\u5230j\u7684\u5b50\u6bb5\u548c <\/span> { \n   <\/span> sum=<\/span>sum+<\/span>array[<\/span>k]<\/span>;<\/span> }<\/span> if<\/span>(<\/span>sum><\/span>Max)<\/span> { \n   <\/span> Max=<\/span>sum;<\/span> }<\/span> }<\/span> }<\/span> return<\/span> Max;<\/span> }<\/span> int<\/span> main<\/span>(<\/span>)<\/span> { \n   <\/span> int<\/span> n;<\/span> cout<<<\/span>\"\u8bf7\u8f93\u5165\u8be5\u5e8f\u5217\u6709\u591a\u5c11\u4e2a\u6570\u5b57\uff1a\"<\/span>;<\/span> cin>><\/span>n;<\/span> int<\/span> array[<\/span>n]<\/span>;<\/span> cout<<<\/span>\"\u8bf7\u4f9d\u6b21\u8f93\u5165\u6570\u5b57\uff1a\"<\/span><<<\/span>endl;<\/span> for<\/span>(<\/span>int<\/span> i=<\/span>0<\/span>;<\/span>i<<\/span>n;<\/span>i++<\/span>)<\/span> { \n   <\/span> cin>><\/span>array<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"\u6700\u5927\u5b50\u6bb5\u548cc++\u4ee3\u7801_c++\u5c40\u90e8\u53d8\u91cf\u548c\u5168\u5c40\u53d8\u91cf\u5b58\u653e\u5728\u54ea\u91cc\u7ed9\u5b9a\u7531n\u4e2a\u6574\u6570\uff08\u53ef\u80fd\u4e3a\u8d1f\u6574\u6570\uff09\u7ec4\u6210\u7684\u5e8f\u5217a[1],a[2],a[3],\u2026,a[n],**\u6700\u5927...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6983"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6983"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6983\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}