{"id":216,"date":"2021-10-25T22:19:17","date_gmt":"2021-10-25T14:19:17","guid":{"rendered":"http:\/\/www.gislxz.top\/?p=216"},"modified":"2021-11-01T20:08:17","modified_gmt":"2021-11-01T12:08:17","slug":"%e7%ae%97%e6%b3%95%ef%bc%881%ef%bc%89%e8%80%90%e5%bf%83%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.gislxz.com\/index.php\/2021\/10\/25\/%e7%ae%97%e6%b3%95%ef%bc%881%ef%bc%89%e8%80%90%e5%bf%83%e6%8e%92%e5%ba%8f\/","title":{"rendered":"\u7b97\u6cd5\uff081\uff09\u8010\u5fc3\u6392\u5e8f"},"content":{"rendered":"\n<p>leetcode\u4e2d\u6709\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u4e00\u9898\uff0c\u9898\u76ee\u8981\u6c42\u5f88\u7b80\u5355\uff0c\u5728\u7ed9\u7684\u65e0\u5e8f\u6570\u7ec4\u4e2d\u6c42\u5f97\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u7684\u957f\u5ea6\u3002<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50nums=[10\uff0c9\uff0c2\uff0c5\uff0c3\uff0c7\uff0c101\uff0c18]\uff0c\u90a3\u4e48\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u662f[2,3,7,101]\uff0c\u7ed3\u679c\u662f4\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u6700\u957f\u5b50\u5e8f\u5217\u4e0d\u552f\u4e00\uff0c\u4f46\u662f\u53ea\u8981\u5f97\u5230\u957f\u5ea6\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u6700\u5bb9\u6613\u60f3\u5230\u7684\u7b97\u6cd5\u4fbf\u662f\u52a8\u6001\u89c4\u5212\u3002\u601d\u8def\u4e5f\u5f88\u7b80\u5355\uff0c\u904d\u5386i\u4ece\u7b2c\u4e00\u4f4d\u5f00\u59cb\uff0c\u5728\u6570\u7ec4\u30100\uff1ai\u3011\u4e2d\u4ee5\u6700\u540e\u4e00\u4f4d\u7ed3\u5c3e\u7684\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u957f\u5ea6\u662f\u591a\u5c11\u3002\u5bf9\u4e0a\u8ff0\u7684nums\uff0c\u663e\u7136i=2\u4e5f\u5c31\u662f\u5728\u524d\u4e09\u4f4d\u6570\u5b57\u7ec4\u6210\u7684\u6570\u7ec4\u4e2d\u4ee5\u7b2c\u4e09\u4f4d\u6570\u5b57\u7ed3\u5c3e\u7684\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u957f\u5ea6\u4e3a1\uff0c\u56e0\u4e3a\u6ca1\u6709\u6570\u5b57\u6bd42\u66f4\u5c0f\uff0c\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u5c31\u662f2\u81ea\u5df1\uff0ci=3\u7ed3\u679c\u4e3a2\uff0c\u5e8f\u5217\u4e3a\u30102\uff0c5\u3011\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u4ee5longest\u6570\u5b57\u5b58\u50a8\u7b2ci\u4f4d\u7ed3\u5c3e\u7684\u6700\u957f\u9012\u589e\u5e8f\u5217\u7ed3\u679c\uff0c\u8ba1\u7b97\u516c\u5f0f\u4e5f\u5f88\u7b80\u5355\uff0c\u904d\u5386\u4e4b\u524d\u7684longest[j]\uff0c\u5728\u6240\u6709\u5c0f\u4e8enum\u3010i\u3011\u7684num\u3010j\u3011\u4e2d\uff08\u8fd9\u6837num\u3010i\u3011\u5c31\u80fd\u63a5\u5728longest\u3010j\u3011\u5bf9\u5e94\u7684\u5e8f\u5217\u540e\u9762\uff09\uff0c\u627e\u51fa\u6700\u5927\u7684longest\u3010j\u3011\u52a01\u5373\u53ef\u3002\u6700\u540e\u904d\u5386longest\u6570\u7ec4\u627e\u5230\u6700\u5927\u7684\u503c\u5373\u4f7f\u7b54\u6848\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\nint longestIncreasingSubsequence(int a&#91;], int length);\n\nint main()\n{\n    int a&#91;] = { 10,9,2,5,3,7,101,18 };\/\/\u65b0\u5efa\u65e0\u9700\u6570\u7ec4\n    int result = longestIncreasingSubsequence(a, 8);\n    cout &lt;&lt; result &lt;&lt; endl;\n}\n\nint longestIncreasingSubsequence(int a&#91;], int length) {\n    int *longest = new int&#91;length];\/\/\u5efa\u7acb\u6570\u7ec4\u5b58\u50a8\u7ed3\u679c\n    for (int i = 0; i &lt; length; i++) {\n        longest&#91;i] = 1;\/\/\u521d\u59cb\u5316\u4e3a1\n        for (int j = 0; j &lt; i; j++) {\n            if (a&#91;i] &gt; a&#91;j]) {\n                longest&#91;i] = max(longest&#91;i], longest&#91;j] + 1);\n            }\n        }\n    }\n    int res = 1;\n    for (int i = 1; i &lt; length; i++) {\n        res = max(res, longest&#91;i]);\n    }\n    return res;\n}<\/code><\/pre>\n\n\n\n<p>\u52a8\u6001\u89c4\u5212\u7684\u65f6\u95f4\u590d\u6742\u5ea6\u662fO\uff08n^2\uff09\uff0c\u7136\u800c\u8fd8\u6709\u4e00\u79cd\u7b97\u6cd5\u80fd\u505a\u5230O(nlogn)\uff0c\u90a3\u5c31\u662f\u8010\u5fc3\u6392\u5e8f\uff0c\u4ee5\u7b97\u6cd5\u4e66\u4e0a\u7684\u6251\u514b\u724c\u4e3e\u4f8b<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1545\" height=\"2560\" src=\"http:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-scaled.jpg\" alt=\"\" class=\"wp-image-218\" srcset=\"https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-scaled.jpg 1545w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-181x300.jpg 181w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-618x1024.jpg 618w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-768x1273.jpg 768w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-927x1536.jpg 927w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c1-1-1236x2048.jpg 1236w\" sizes=\"auto, (max-width: 1545px) 100vw, 1545px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"2560\" height=\"1440\" src=\"http:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-scaled.jpg\" alt=\"\" class=\"wp-image-219\" srcset=\"https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-scaled.jpg 2560w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-300x169.jpg 300w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-1024x576.jpg 1024w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-768x432.jpg 768w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-1536x864.jpg 1536w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/\u6251\u514b\u724c2-2048x1152.jpg 2048w\" sizes=\"auto, (max-width: 2560px) 100vw, 2560px\" \/><\/figure>\n\n\n\n<p>\u7b97\u6cd5\u5f88\u5de7\u5999\uff0c\u90a3\u4e48\u4e3a\u4ec0\u4e48\u5806\u6570\u5c31\u662f\u6700\u957f\u9012\u589e\u5e8f\u5217\u7684\u957f\u5ea6\u5462\uff1f<\/p>\n\n\n\n<p>\u9996\u5148\u601d\u8003\u653e\u724c\u89c4\u5219\u6211\u4eec\u6a21\u62df\u53d6\u724c\u7684\u64cd\u4f5c\uff08\u53d6\u724c\u5373\u7b49\u4ef7\u4e8e\u5bfb\u627e\u6700\u957f\u9012\u589e\u5e8f\u5217\uff09\u80fd\u5f97\u51fa\u4ee5\u4e0b\u51e0\u4e2a\u7ed3\u8bba\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>1\u53ef\u4ee5\u4ece\u4efb\u4e00\u5806\u4e2d\u5f00\u59cb\u53d6\u724c<\/li><li>2\u4e0b\u4e00\u5f20\u724c\u4e0d\u80fd\u662f\u540c\u5806\u7684\u724c\uff08\u6bd4\u5f53\u524d\u724c\u5927\u7684\u4e00\u5b9a\u5728\u4e0a\u65b9\uff0c\u5373\u5728\u6570\u7ec4\u4e2d\u5728\u5f53\u524d\u6570\u5b57\u524d\u9762\uff0c\u4e0d\u80fd\u5411\u524d\u9009\uff09<\/li><li>3\u4e0b\u4e00\u5f20\u724c\u4e0d\u80fd\u5411\u524d\u9762\u7684\u5806\u53d6\uff08\u524d\u9762\u5806\u4e2d\u6bd4\u5f53\u524d\u724c\u5927\u7684\u4e00\u5b9a\u5728\u6570\u7ec4\u4e2d\u5148\u51fa\u73b0\uff0c\u53ea\u662f\u7531\u4e8e\u8be5\u724c\u7684\u4e0b\u9762\u53c8\u76d6\u4e0a\u4e86\u5c0f\u724c\u5bfc\u81f4\u5f53\u524d\u724c\u53ea\u80fd\u653e\u5728\u53f3\u8fb9\uff09<\/li><\/ul>\n\n\n\n<p>\u56e0\u6b64\u53d6\u724c\u7684\u987a\u5e8f\u53ea\u80fd\u662f\u5411\u53f3\u9762\u7684\u5806\u53d6\uff0c\u90a3\u4e48\u6700\u957f\u7684\u5e8f\u5217\u4e00\u5b9a\u662f\u4ece\u5de6\u5230\u53f3\u4e00\u5806\u53d6\u4e00\u5f20\uff0c\u4f46\u662f\u4e0d\u53ef\u60f3\u5f53\u7136\u7684\u8ba4\u4e3a\u6700\u957f\u9012\u589e\u5e8f\u5217\u5c31\u662f\u6bcf\u5806\u7684\u6700\u4e0b\u9762\u4e00\u5f20\u724c\u4ece\u5de6\u5230\u53f3\u8fde\u8d77\u6765\uff0c\u56e0\u4e3a\u8fd9\u4e9b\u724c\u5728\u6570\u7ec4\u4e2d\u5e76\u4e0d\u4e00\u5b9a\u7b26\u5408\u4ece\u524d\u5230\u540e\u7684\u51fa\u73b0\u987a\u5e8f\u3002\u6240\u4ee5\u6211\u4eec\u8fd8\u8981\u8bc1\u660e\u80fd\u591f\u505a\u5230\u4e00\u5806\u53d6\u4e00\u5f20\u6784\u6210\u6700\u957f\u9012\u589e\u5e8f\u5217\u3002<\/p>\n\n\n\n<p>\u8981\u8bc1\u660e\u4e00\u5b9a\u80fd\u4e00\u5806\u53d6\u4e00\u5f20\uff0c\u53ea\u8981\u8bc1\u660e\u5bf9\u4efb\u4e00\u4e00\u4e2a\u5806\uff0c\u4e00\u5b9a\u80fd\u627e\u51fa\u4e00\u5f20\u724c\uff0c\u6bd4\u524d\u4e00\u4e2a\u5806\u7684\u4e00\u5f20\u724c\u5927\u4e14\u5728\u6570\u7ec4\u4e2d\u6392\u5728\u540e\u9762<\/p>\n\n\n\n<p>\u8fd9\u4e5f\u5f88\u597d\u8bc1\u660e\uff0c\u653e\u724c\u65f6\u6bcf\u4e00\u5f20\u724c\u4e00\u5b9a\u6bd4\u524d\u4e00\u5806\u7684\u6700\u540e\u4e00\u5f20\u724c\u8981\u5927\u4e14\u6392\u5728\u540e(\u7b2c\u4e8c\u5f20\u56fe\u5c31\u662f\u4ece\u540e\u5411\u524d\uff0c\u6bcf\u5f20\u724c\u5bf9\u5e94\u7684\u5f53\u65f6\u524d\u5806\u6700\u540e\u4e00\u5f20\u724c\uff0c\u770b\u56fe\u53ef\u4ee5\u77e5\u9053\u6700\u957f\u9012\u589e\u5e8f\u5217\u6709\u4e09\u4e2a\u89e3)\uff0c\u4e5f\u5c31\u81ea\u7136\u6ee1\u8db3\u4e0a\u9762\u8bf4\u7684\u8fd9\u4e2a\u6761\u4ef6\u3002<\/p>\n\n\n\n<p>\u81ea\u6b64\u6211\u4eec\u5c31\u80fd\u8bc1\u660e\u5806\u6570\u5c31\u662f\u6700\u957f\u9012\u589e\u5e8f\u5217\u7684\u957f\u5ea6<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u53ea\u8981\u6a21\u62df\u653e\u724c\u7684\u8fc7\u7a0b<\/p>\n\n\n\n<p>\u6ce8\u610f\u5230\u6bcf\u5806\u7684\u6700\u4e0b\u9762\u90a3\u5f20\u724c\uff08\u4e5f\u5c31\u662f\u5806\u9876\uff09\u4ece\u5de6\u5230\u53f3\u662f\u9012\u589e\u7684\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e8c\u5206\u641c\u7d22\u6cd5\u6700\u5927\u5316\u6548\u7387<\/p>\n\n\n\n<p>\u7531\u4e8e\u9898\u76ee\u53ea\u8981\u6c42\u5f97\u957f\u5ea6\u800c\u4e0d\u9700\u7ed9\u51fa\u5e8f\u5217\uff0c\u6240\u4ee5\u6211\u4eec\u8fde\u5806\u90fd\u4e0d\u7528\u8bb0\u5f55\uff0c\u53ea\u8bb0\u5f55\u5806\u9876\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u51fd\u6570\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int patienceSorting(int a&#91;], int length) {\n    int* top = new int(length);\/\/\u8bb0\u5f55\u5806\u9876\n    int piles = 0;\/\/\u8bb0\u5f55\u5806\u6570\n    for (int i = 0; i &lt; length; i++) {\n        int poker = a&#91;i];\/\/\u5f53\u524d\u724c\n        \/\/\u4e8c\u5206\u641c\u7d22\n        int left = 0, right = piles;\n        while (left &lt; right) {\n            int mid = (left + right) \/ 2;\n            if (top&#91;mid] &gt; poker)\n                right = mid;\n            else if (top&#91;mid] &lt; poker)\n                left = mid + 1;\n            else\n                right = mid;\n        }\n        if (left == piles) \n            piles++;\/\/\u9700\u8981\u65b0\u5efa\u5806\u7684\u60c5\u51b5\n        top&#91;left] = poker;\n    }\n    return piles;\n}<\/code><\/pre>\n\n\n\n<p>\u4e8c\u5206\u641c\u7d22\u4e0b\u6b21\u8865\u4e0a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"793\" src=\"http:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/1.jpg\" alt=\"\" class=\"wp-image-220\" srcset=\"https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/1.jpg 800w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/1-300x297.jpg 300w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/1-150x150.jpg 150w, https:\/\/www.gislxz.com\/wp-content\/uploads\/2021\/10\/1-768x761.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u957f\u9012\u589e\u5b50\u5e8f\u5217\u2014\u2014\u4ece\u52a8\u6001\u89c4\u5212\u5230\u8010\u5fc3\u6392\u5e8f\u7684\u5b9e\u73b0<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-216","post","type-post","status-publish","format-standard","hentry","category-11"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/comments?post=216"}],"version-history":[{"count":4,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions"}],"predecessor-version":[{"id":226,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/posts\/216\/revisions\/226"}],"wp:attachment":[{"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/media?parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/categories?post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gislxz.com\/index.php\/wp-json\/wp\/v2\/tags?post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}