{"id":741,"date":"2020-07-30T10:57:18","date_gmt":"2020-07-30T02:57:18","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=741"},"modified":"2020-07-30T14:07:59","modified_gmt":"2020-07-30T06:07:59","slug":"%e5%b8%a6%e6%9d%83%e6%9c%89%e5%90%91%e5%9b%be%e6%b1%82lis","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2020\/07\/30\/%e5%b8%a6%e6%9d%83%e6%9c%89%e5%90%91%e5%9b%be%e6%b1%82lis\/","title":{"rendered":"\u5e26\u6743\u6709\u5411\u56fe\u6c42LIS"},"content":{"rendered":"<h4><a href=\"https:\/\/codeforces.com\/contest\/459\/problem\/E\">CF459E Pashmak and Graph<\/a><\/h4>\n<p>\u7ed9\u4e00\u4e2a\u5e26\u6743\u6709\u5411\u56fe\uff0c\u6c42\u5176\u4e2d\u4e25\u683c\u9012\u589e\u7684\u6700\u957f\u8def\u5f84\u7684\u957f\u5ea6(\u7b97\u8fb9\u6570)\u3002<\/p>\n<p>\u5206\u6790\uff1a\u7b2c\u4e00\u773c\u60f3\u5230\u7684\u80af\u5b9a\u662fdp\uff0c\u4ee4f[i]\u8868\u793a\u4ee5\u7ed3\u70b9i\u7ed3\u5c3e\u7684\u6700\u957f\u8def\u5f84\u957f\u5ea6\uff0c\u4f46\u662f\u53d1\u73b0\u6709\u540e\u6548\u6027\uff0c\u6ca1\u529e\u6cd5\u6ef4\u51fa\u7b54\u6848\u3002\u53ef\u4ee5\u5148\u5bf9\u8fb9\u6743\u4ece\u5c0f\u5230\u5927\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u626b\u63cf\u8fb9\uff0c\u8fd9\u6837\u53ef\u4ee5\u4e0d\u7528\u8003\u8651\u8fb9\u6743\u4e4b\u95f4\u7684\u7ea6\u675f\u5173\u7cfb\u3002\u5047\u8bbe\u626b\u63cf\u5230\u4e00\u6761\u8fb9e[i]\uff0c\u4eceu\u6307\u5411v\uff0c\u90a3\u4e48\u53ef\u4ee5\u76f4\u63a5\u66f4\u65b0f[v] = max(f[u]+1, f[v])\uff0c\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u76f4\u63a5\u66f4\u65b0\u5462\uff1f\u56e0\u4e3af[u]\u662f\u7531e[i]\u524d\u9762\u90a3\u4e9b\u8fb9\u6743\u5c0f\u4e8ee[i]\u7684\u8fb9\u6784\u6210\u7684\uff0c\u4e0d\u7528\u8003\u8651\u8fb9\u6743\u7684\u7ea6\u675f\u3002<br \/>\n\u4f46\u662f\u8fd9\u6837\u6700\u540e\u6c42\u51fa\u6765\u7684\u7b54\u6848\u4e0d\u662f\u4e25\u683c\u9012\u589e\u7684\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u8003\u8651\u90a3\u4e9b\u8fb9\u6743\u76f8\u540c\u7684\u8fb9\u5e26\u6765\u7684\u76f8\u4e92\u5f71\u54cd\u3002\u6211\u4eec\u53ef\u4ee5\u5bf9\u8fb9\u6743\u76f8\u540c\u7684\u8fb9\u4e00\u8d77\u8003\u8651\uff0c\u5047\u8bbee[i]\u5230e[j]\u7684\u8fb9\u6743\u76f8\u540c\uff0c\u73b0\u5728\u4e00\u6b21\u626b\u63cf\u8fd9\u4e9b\u8fb9\uff0c\u628a\u9700\u8981\u66f4\u65b0\u7684f[i]\u5148\u5b58\u5230g[i]\u91cc\u9762\uff0c\u7b49\u8fd9\u4e9b\u8fb9\u6743\u76f8\u540c\u7684\u8fb9\u5168\u90e8\u8003\u8651\u5b8c\u4e4b\u540e\uff0c\u518d\u628ag[]\u91cc\u7684\u503c\u8d4b\u7ed9f[]\u3002\u8fd9\u6837\u5c31\u884c\u4e86\u3002<\/p>\n<pre><code class=\"language-c++\">#include &lt;cstdio&gt;\n#include &lt;algorithm&gt;\n\nusing namespace std;\nconst int maxn = 3e5+5;\nstruct edge{\n    int u, v, w;\n    friend bool operator &lt; (const struct edge &amp;a, const struct edge &amp;b){\n        return a.w &lt; b.w;\n    }\n}e[maxn];\nint n, m;\nint f[maxn], g[maxn];          \/\/ f[v] = max(f[v], f[u]+1)\nint sta[maxn], top;\ninline int read(){\n    int x=0; char ch = getchar();\n    while (ch&lt;&#039;0&#039; || ch&gt;&#039;9&#039;)    ch = getchar();\n    while (ch&gt;=&#039;0&#039; &amp;&amp; ch&lt;=&#039;9&#039;){\n        x = x*10 + ch-&#039;0&#039;;\n        ch = getchar();\n    }\n    return x;\n}\nint main(){\n    int ans = 0;\n    n = read(), m = read();\n    for (int i=1; i&lt;=m; i++)    e[i].u = read(), e[i].v = read(), e[i].w = read();\n    sort (e+1, e+m+1);\n    top = 0;\n    for (int i=1; i&lt;=m; ){\n        int j = i;\n        while (e[i].w == e[j+1].w)  j++;\n        for (int k=i; k&lt;=j; k++)    if (f[e[k].u]+1 &gt; f[e[k].v]){\n            g[e[k].v] = max (f[e[k].u] + 1, g[e[k].v]);\n            sta[++top] = e[k].v;\n        }\n        while (top){\n            f[sta[top]] = max(f[sta[top]], g[sta[top]]);\n            g[sta[top]] = 0;\n            top--;\n        }\n        i = j+1;\n    }\n    for (int i=1; i&lt;=n; i++)    ans = max(ans, f[i]);\n    printf (&quot;%d&quot;, ans);\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CF459E Pashmak and Graph \u7ed9\u4e00\u4e2a\u5e26\u6743\u6709\u5411\u56fe\uff0c\u6c42\u5176\u4e2d\u4e25\u683c\u9012\u589e\u7684\u6700\u957f\u8def\u5f84\u7684\u957f\u5ea6( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[54],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/741"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=741"}],"version-history":[{"count":3,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/741\/revisions"}],"predecessor-version":[{"id":744,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/741\/revisions\/744"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=741"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}