{"id":35,"date":"2026-02-21T23:55:49","date_gmt":"2026-02-21T15:55:49","guid":{"rendered":"https:\/\/blog.mirpri.com\/?p=35"},"modified":"2026-02-22T13:42:04","modified_gmt":"2026-02-22T05:42:04","slug":"luogu-p1020","status":"publish","type":"post","link":"https:\/\/blog.mirpri.com\/index.php\/luogu-p1020\/","title":{"rendered":"P1020 \u5bfc\u5f39\u62e6\u622a"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u9898\u76ee\u63cf\u8ff0<\/h2>\n\n\n\n<p>\u67d0\u56fd\u4e3a\u4e86\u9632\u5fa1\u654c\u56fd\u7684\u5bfc\u5f39\u88ad\u51fb\uff0c\u53d1\u5c55\u51fa\u4e00\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u3002\u4f46\u662f\u8fd9\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u6709\u4e00\u4e2a\u7f3a\u9677\uff1a\u867d\u7136\u5b83\u7684\u7b2c\u4e00\u53d1\u70ae\u5f39\u80fd\u591f\u5230\u8fbe\u4efb\u610f\u7684\u9ad8\u5ea6\uff0c\u4f46\u662f\u4ee5\u540e\u6bcf\u4e00\u53d1\u70ae\u5f39\u90fd\u4e0d\u80fd\u9ad8\u4e8e\u524d\u4e00\u53d1\u7684\u9ad8\u5ea6\u3002\u67d0\u5929\uff0c\u96f7\u8fbe\u6355\u6349\u5230\u654c\u56fd\u7684\u5bfc\u5f39\u6765\u88ad\u3002\u7531\u4e8e\u8be5\u7cfb\u7edf\u8fd8\u5728\u8bd5\u7528\u9636\u6bb5\uff0c\u6240\u4ee5\u53ea\u6709\u4e00\u5957\u7cfb\u7edf\uff0c\u56e0\u6b64\u6709\u53ef\u80fd\u4e0d\u80fd\u62e6\u622a\u6240\u6709\u7684\u5bfc\u5f39\u3002<\/p>\n\n\n\n<p>\u8f93\u5165\u5bfc\u5f39\u4f9d\u6b21\u98de\u6765\u7684\u9ad8\u5ea6\uff0c\u8ba1\u7b97\u8fd9\u5957\u7cfb\u7edf\u6700\u591a\u80fd\u62e6\u622a\u591a\u5c11\u5bfc\u5f39\uff0c\u5982\u679c\u8981\u62e6\u622a\u6240\u6709\u5bfc\u5f39\u6700\u5c11\u8981\u914d\u5907\u591a\u5c11\u5957\u8fd9\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u3002<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-outline is-style-outline--1\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.luogu.com.cn\/problem\/P1020\">Luogu P1020<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u7b54<\/h2>\n\n\n\n<p>\u7b2c\u4e00\u95ee\uff1a\u6c42\u6570\u5217\u7684<strong>\u6700\u957f<em>\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u957f\u5ea6<\/em><\/strong><\/p>\n\n\n\n<p>\u7b2c\u4e8c\u95ee\uff1a\u6c42<strong>\u6700\u5c11\u7684<em>\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u8986\u76d6\u6570<\/em><\/strong><\/p>\n\n\n\n<p>\u6839\u636e Dilworth \u5b9a\u7406\uff0c\u6700\u5c11\u7684\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u8986\u76d6\u6570\u7b49\u4e8e&nbsp;<strong>\u6700\u957f\u4e0a\u5347\u5b50\u5e8f\u5217 (Longest Increasing Subsequence, LIS)<\/strong>&nbsp;\u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u4e24\u4e2a\u95ee\u9898\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002<\/p>\n\n\n\n<p>\u5148\u8bf4\u7b97\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u7b2c\u4e00\u95ee\uff08\u6700\u957f\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\uff09<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u7ef4\u62a4\u4e00\u4e2a<strong>\u975e\u9012\u589e<\/strong>\u7684\u8f85\u52a9\u6570\u7ec4&nbsp;<code>dp1<\/code>\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u5f53\u524d\u5143\u7d20&nbsp;<code>M[i]<\/code>&nbsp;\u5c0f\u4e8e\u7b49\u4e8e&nbsp;<code>dp1<\/code>&nbsp;\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u76f4\u63a5\u8ffd\u52a0\u3002<\/li>\n\n\n\n<li>\u5426\u5219\uff0c\u7528&nbsp;<code>upper_bound<\/code> \u5728&nbsp;<code>dp1<\/code>&nbsp;\u4e2d\u627e\u5230\u7b2c\u4e00\u4e2a<strong>\u5c0f\u4e8e<\/strong>&nbsp;<code>M[i]<\/code>&nbsp;\u7684\u6570\u5e76\u66ff\u6362\u5b83\u3002\u8fd9\u6837\u53ef\u4ee5\u8ba9\u5b50\u5e8f\u5217\u66f4\u6709\u6f5c\u529b\u63a5\u7eb3\u66f4\u591a\u5143\u7d20\u3002<\/li>\n\n\n\n<li>\u6700\u7ec8&nbsp;<code>dp1.size()<\/code>&nbsp;\u5c31\u662f\u7b54\u6848\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u7b2c\u4e8c\u95ee\uff08\u6700\u5c11\u7cfb\u7edf\u6570 = \u6700\u957f\u4e0a\u5347\u5b50\u5e8f\u5217\uff09<\/strong>\uff1a\n<ul class=\"wp-block-list\">\n<li>\u7ef4\u62a4\u4e00\u4e2a<strong>\u9012\u589e<\/strong>\u7684\u8f85\u52a9\u6570\u7ec4&nbsp;<code>dp2<\/code>\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u5f53\u524d\u5143\u7d20&nbsp;<code>M[i]<\/code>&nbsp;\u5927\u4e8e&nbsp;<code>dp2<\/code>&nbsp;\u7684\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u76f4\u63a5\u8ffd\u52a0\u3002<\/li>\n\n\n\n<li>\u5426\u5219\uff0c\u7528&nbsp;<code>lower_bound<\/code>&nbsp;\u5728&nbsp;<code>dp2<\/code>&nbsp;\u4e2d\u627e\u5230\u7b2c\u4e00\u4e2a<strong>\u5927\u4e8e\u7b49\u4e8e<\/strong>&nbsp;<code>M[i]<\/code>&nbsp;\u7684\u6570\u5e76\u66ff\u6362\u5b83\u3002<\/li>\n\n\n\n<li>\u6700\u7ec8&nbsp;<code>dp2.size()<\/code>&nbsp;\u5c31\u662f\u7b54\u6848\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<p>\u7b2c\u4e8c\u95ee\u6bd4\u8f83\u5bb9\u6613\u7528\u8d2a\u5fc3\u7684\u601d\u8def\u6765\u7406\u89e3\uff1a<\/p>\n\n\n\n<p>\u5c06dp\u6570\u7ec4\u7684\u503c\u770b\u6210\u76ee\u524d\u7528\u8fc7\u7684\u6240\u6709\u5bfc\u5f39\u9ad8\u5ea6\u7684\u4e0a\u9650\uff0c\u6309\u987a\u5e8f\u904d\u5386\u6240\u6709\u76ee\u6807\uff0c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6bcf\u6b21\u9009\u53d6\u6ee1\u8db3\u8981\u6c42\u4e14<em>\u4e0a\u4e00\u53d1\u6253\u5f97\u6700\u4f4e<\/em>\u7684\u5bfc\u5f39\u6765\u6253\u65b0\u7684\u76ee\u6807\uff0c\u8fd9\u6837\u51cf\u5c11\u6d6a\u8d39\uff0c\u4fdd\u8bc1\u8fd9\u4e00\u53d1\u6253\u5b8c\u4ee5\u540e\u5404\u4e2a\u5bfc\u5f39\u7684\u4e0a\u9650\u6700\u9ad8\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u4e0b\u4e00\u4e2a\u76ee\u6807\u6bd4\u4e4b\u524d\u6240\u6709\u5bfc\u5f39\u4e0a\u4e00\u53d1\u90fd\u9ad8\uff0c\u53ea\u80fd\u65b0\u5f00\u4e00\u4e2a\u5bfc\u5f39\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u6253\u5b8c\u4ee5\u540e\u5c06\u5bfc\u5f39\u7684\u9ad8\u5ea6\u4e0a\u9650\u6539\u4e3a\u8fd9\u4e2a\u76ee\u6807\u7684\u9ad8\u5ea6\u3002\u6b63\u597d\uff0c\u65e0\u8bba\u5bf9\u5df2\u6709\u7684\u5bfc\u5f39\u8fd8\u662f\u65b0\u589e\u7684\u5bfc\u5f39\uff0c\u66f4\u65b0\u4e3a\u65b0\u7684\u76ee\u6807\u7684\u9ad8\u5ea6\u540e\u5747\u80fd\u4fdd\u6301\u6570\u7ec4\u4ecd\u7136\u5355\u8c03\u9012\u589e\uff0c\u4e3a\u8fd0\u7528\u4e8c\u5206\u67e5\u627e\u63d0\u4f9b\u4e86\u6761\u4ef6\u3002<\/p>\n\n\n\n<p>Dilworth \u5b9a\u7406\u6697\u793a\u7740\u7b2c\u4e00\u95ee\u4e5f\u80fd\u4f7f\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff0c\u4f46\u4e0d\u5982\u7b2c\u4e8c\u95ee\u76f4\u89c2\u3002\u8bfb\u8005\u53ef\u5c1d\u8bd5\u81ea\u884c\u89e3\u91ca\u3002\u6211\u7684\u4e00\u79cd\u89e3\u91ca\u662f\uff1a\u5c06\u6b64\u65f6\u7684 dp \u6570\u7ec4\u770b\u4f5c\u6240\u6c42\u7684\u6700\u957f\u5355\u8c03\u5b50\u5e8f\u5217\u7684\u53d8\u4f53\uff0c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u4e0b\u4e00\u4e2a\u5143\u7d20\u6bd4\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u5c0f\u65f6\uff0c\u81ea\u7136\u53ef\u4ee5\u76f4\u63a5\u52a0\u5165\u5b50\u5e8f\u5217\uff0c\u4f7f\u957f\u5ea6 +1 \u3002<\/li>\n\n\n\n<li>\u5426\u5219\uff0c\u627e\u5230\u8be5\u5143\u7d20<em>\u53ef\u4ee5\u51fa\u73b0\u7684\u6700\u665a\u7684\u4f4d\u7f6e<\/em>\uff0c\u628a\u5b83\u653e\u5728\u8fd9\u91cc\uff0c\u4f7f\u8be5\u5904\u7684\u503c\u53d8\u5927\uff0c\u4f7f\u5f97\u4ee5\u540e\u66f4\u591a\u5143\u7d20\uff08\u5927\u4e8e\u539f\u6765\u503c\u4f46\u4e0d\u5927\u4e8e\u65b0\u7684\u503c\u7684\u5143\u7d20\uff09\u53ef\u4ee5\u63a5\u5728\u5b83\u540e\u9762\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8fd9\u6837\uff0cdp \u7b2c i \u4f4d\u8868\u793a\u957f\u5ea6\u4e3a i \u65f6\uff0c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0a\u9650\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">AC\u4ee3\u7801<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\nusing namespace std;\n\nconst int mm = 100100;\nvector&lt;int&gt; v1,v2;\nint n, h&#91;mm];\n\nbool rev(const int &amp;a, const int &amp;b){\n  return a&gt;b;\n}\n\nint main(){\n  int tmp;\n  while (cin&gt;&gt;tmp) {\n    h&#91;n++]=tmp;\n  }\n  \n  v1.push_back(h&#91;0]);\n  for (int i=1; i&lt;n; i++) {\n    if(h&#91;i]&lt;=v1.back()) {\n      v1.push_back(h&#91;i]);\n      continue;\n    }\n    auto p=upper_bound(v1.begin(), v1.end(), h&#91;i], rev);\n    *p=h&#91;i];\n  }\n  cout&lt;&lt;v1.size()&lt;&lt;endl;\n\n  v2.push_back(h&#91;1]);\n  for (int i=0; i&lt;n; i++) {\n    if(h&#91;i]&gt;v2.back()) {\n      v2.push_back(h&#91;i]);\n      continue;\n    }\n    auto p=lower_bound(v2.begin(), v2.end(), h&#91;i]);\n    *p=h&#91;i];\n  }\n  cout&lt;&lt;v2.size();\n\n  return 0;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u76f8\u5173\u9898<\/h2>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button is-style-outline is-style-outline--2\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/www.luogu.com.cn\/problem\/P1091\">P1091 [NOIP 2004 \u63d0\u9ad8\u7ec4] \u5408\u5531\u961f\u5f62<\/a><\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u67d0\u56fd\u4e3a\u4e86\u9632\u5fa1\u654c\u56fd\u7684\u5bfc\u5f39\u88ad\u51fb\uff0c\u53d1\u5c55\u51fa\u4e00\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u3002\u4f46\u662f\u8fd9\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u6709\u4e00\u4e2a\u7f3a\u9677\uff1a\u867d\u7136\u5b83\u7684\u7b2c\u4e00\u53d1\u70ae\u5f39\u80fd\u591f\u5230\u8fbe\u4efb\u610f\u7684\u9ad8\u5ea6\uff0c\u4f46\u662f\u4ee5\u540e\u6bcf\u4e00\u53d1\u70ae\u5f39\u90fd\u4e0d\u80fd\u9ad8\u4e8e\u524d\u4e00\u53d1\u7684\u9ad8\u5ea6\u3002\u67d0\u5929\uff0c\u96f7\u8fbe\u6355\u6349\u5230\u654c\u56fd\u7684\u5bfc\u5f39\u6765\u88ad\u3002\u7531\u4e8e\u8be5\u7cfb\u7edf\u8fd8\u5728\u8bd5\u7528\u9636\u6bb5\uff0c\u6240\u4ee5\u53ea\u6709\u4e00\u5957\u7cfb\u7edf\uff0c\u56e0\u6b64\u6709\u53ef\u80fd\u4e0d\u80fd\u62e6\u622a\u6240\u6709\u7684\u5bfc\u5f39\u3002 \u8f93\u5165\u5bfc\u5f39\u4f9d\u6b21\u98de\u6765\u7684\u9ad8\u5ea6\uff0c\u8ba1\u7b97\u8fd9\u5957\u7cfb\u7edf\u6700\u591a\u80fd\u62e6\u622a\u591a\u5c11\u5bfc\u5f39\uff0c\u5982\u679c\u8981\u62e6\u622a\u6240\u6709\u5bfc\u5f39\u6700\u5c11\u8981\u914d\u5907\u591a\u5c11\u5957\u8fd9\u79cd\u5bfc\u5f39\u62e6\u622a\u7cfb\u7edf\u3002 \u89e3\u7b54 \u7b2c\u4e00\u95ee\uff1a\u6c42\u6570\u5217\u7684\u6700\u957f\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u957f\u5ea6 \u7b2c\u4e8c\u95ee\uff1a\u6c42\u6700\u5c11\u7684\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u8986\u76d6\u6570 \u6839\u636e Dilworth \u5b9a\u7406\uff0c\u6700\u5c11\u7684\u4e0d\u4e0a\u5347\u5b50\u5e8f\u5217\u8986\u76d6\u6570\u7b49\u4e8e&nbsp;\u6700\u957f\u4e0a\u5347\u5b50\u5e8f\u5217 (Longest Increasing Subsequence, LIS)&nbsp;\u7684\u957f\u5ea6\uff0c\u56e0\u6b64\u4e24\u4e2a\u95ee\u9898\u53ef\u4ee5\u76f8\u4e92\u8f6c\u5316\u3002 \u5148\u8bf4\u7b97\u6cd5\uff1a \u7b2c\u4e8c\u95ee\u6bd4\u8f83\u5bb9\u6613\u7528\u8d2a\u5fc3\u7684\u601d\u8def\u6765\u7406\u89e3\uff1a \u5c06dp\u6570\u7ec4\u7684\u503c\u770b\u6210\u76ee\u524d\u7528\u8fc7\u7684\u6240\u6709\u5bfc\u5f39\u9ad8\u5ea6\u7684\u4e0a\u9650\uff0c\u6309\u987a\u5e8f\u904d\u5386\u6240\u6709\u76ee\u6807\uff0c \u6253\u5b8c\u4ee5\u540e\u5c06\u5bfc\u5f39\u7684\u9ad8\u5ea6\u4e0a\u9650\u6539\u4e3a\u8fd9\u4e2a\u76ee\u6807\u7684\u9ad8\u5ea6\u3002\u6b63\u597d\uff0c\u65e0\u8bba\u5bf9\u5df2\u6709\u7684\u5bfc\u5f39\u8fd8\u662f\u65b0\u589e\u7684\u5bfc\u5f39\uff0c\u66f4\u65b0\u4e3a\u65b0\u7684\u76ee\u6807\u7684\u9ad8\u5ea6\u540e\u5747\u80fd\u4fdd\u6301\u6570\u7ec4\u4ecd\u7136\u5355\u8c03\u9012\u589e\uff0c\u4e3a\u8fd0\u7528\u4e8c\u5206\u67e5\u627e\u63d0\u4f9b\u4e86\u6761\u4ef6\u3002 Dilworth \u5b9a\u7406\u6697\u793a\u7740\u7b2c\u4e00\u95ee\u4e5f\u80fd\u4f7f\u7528\u7c7b\u4f3c\u7684\u65b9\u6cd5\uff0c\u4f46\u4e0d\u5982\u7b2c\u4e8c\u95ee\u76f4\u89c2\u3002\u8bfb\u8005\u53ef\u5c1d\u8bd5\u81ea\u884c\u89e3\u91ca\u3002\u6211\u7684\u4e00\u79cd\u89e3\u91ca\u662f\uff1a\u5c06\u6b64\u65f6\u7684 dp \u6570\u7ec4\u770b\u4f5c\u6240\u6c42\u7684\u6700\u957f\u5355\u8c03\u5b50\u5e8f\u5217\u7684\u53d8\u4f53\uff0c \u8fd9\u6837\uff0cdp \u7b2c i \u4f4d\u8868\u793a\u957f\u5ea6\u4e3a i \u65f6\uff0c\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u4e0a\u9650\u3002 AC\u4ee3\u7801 \u76f8\u5173\u9898<\/p>\n","protected":false},"author":4,"featured_media":43,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-35","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-algorithm"],"_links":{"self":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/comments?post=35"}],"version-history":[{"count":0,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/posts\/35\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/media\/43"}],"wp:attachment":[{"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/categories?post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mirpri.com\/index.php\/wp-json\/wp\/v2\/tags?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}