{"id":900,"date":"2019-08-08T14:50:02","date_gmt":"2019-08-08T06:50:02","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=900"},"modified":"2019-08-15T19:27:34","modified_gmt":"2019-08-15T11:27:34","slug":"lp2515-haoi2010-%e8%bd%af%e4%bb%b6%e5%ae%89%e8%a3%85","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2019\/08\/08\/lp2515-haoi2010-%e8%bd%af%e4%bb%b6%e5%ae%89%e8%a3%85\/","title":{"rendered":"lp2515 HAOI2010 \u8f6f\u4ef6\u5b89\u88c5"},"content":{"rendered":"\n<p> \u7b80\u5355\u7684tarjan\u7f29\u70b9+\u6811\u5f62\u80cc\u5305DP\u3002<br> \u8003\u8651N&lt;=100\uff0cM&lt;=500\uff0c\u53ea\u9700\u8981\u8bbef[i][j]\u8868\u793a\u7b2ci\u4e2a\u70b9\uff0c\u5df2\u7528j\u7684\u5bb9\u91cf\u3002<br> \u7136\u540e\u76f4\u63a5DP\u5373\u53ef\u3002 <br> \u7279\u522b\u5730\uff0c\u7531\u4e8e\u5982\u679c\u67d0\u4e00\u4e2a\u70b9\u7684\u5b50\u6811\u4e2d\u7684\u70b9\u88ab\u9009\u4e2d\u4e86\uff0c\u8fd9\u4e2a\u70b9\u4e5f\u8981\u88ab\u9009\u4e2d\uff0c\u6240\u4ee5\u6211\u4eec\u5728\u8ba1\u7b97\u6bcf\u4e2a\u70b9\u7684\u65f6\u5019\uff0c\u4e00\u5b9a\u8981\u5c06\u8fd9\u4e2a\u70b9\u52a0\u8fdb\u53bb\u3002<br> \u7136\u540e\u4ed4\u7ec6\u770b\u770b\u8fd9\u9053\u9898\uff0c\u53d1\u73b0\u5b83\u4e0d\u4fdd\u8bc1\u6ca1\u6709\u73af\uff01<br> \u8fd9\u4e0b\u5b8c\u86cb\u4e86\uff0c\u548b\u505a\u554a\uff1f<br> \u8003\u8651\u5230\u8fd9\u4e2a\u73af\u8981\u4e48\u90fd\u9009\uff0c\u8981\u4e48\u90fd\u4e0d\u9009\uff0c\u6240\u4ee5\u53ef\u4ee5\u5148\u7528tarjan\u627e\u73af\uff0c\u628a\u627e\u73af\u540e\u7684\u70b9\u62ff\u6765dfs\u3002<br> \u7136\u540e\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u6027\u8d28\uff1a\u5982\u679c\u5b58\u5728\u73af\uff0c\u90a3\u4e48\u8fd9\u4e2a\u73af\u7f29\u6210\u7684\u70b9\u4e00\u5b9a\u662f\u67d0\u4e00\u68f5\u6811\u7684\u6811\u6839\u3002 <br> \u6240\u4ee5\u6211\u4eec\u4e0d\u59a8\u8ba1\u7b97\u6bcf\u4e00\u4e2a\u70b9\u7684\u5165\u5ea6\uff0c\u7136\u540e\u5c06\u5165\u5ea6\u4e3a0\u7684\u70b9\u8fde\u5411\u865a\u70b90\u3002\u8fd9\u6837\u53ea\u9700\u8981\u4e00\u6b21DP\u3002 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;cstring>\n#include&lt;algorithm>\n#include&lt;queue>\n#include&lt;vector>\nusing namespace std;\n\ninline int Max(int A,int B){\n\treturn A>B?A:B;\n}\ninline int Min(int A,int B){\n\treturn A&lt;B?A:B;\n}\nstruct ee{\n\tint v;\n\tint nxt;\n}e[505];\nint h[505],g[505],et=0;\ninline void add(int *H,int U,int V){\n\te[++et]=(ee){V,H[U]};\n\tH[U]=et;\n}\nint n,m,f[505][505],w[505],v[505],ww[505],val[505],d[505],in[505];\nint vis[505],clr[505],dfn[505],lw[505],cnt=0,ccnt=0,st[505],tp=0;\ninline void dfs0(int X){\n\tvis[X]=1,dfn[X]=lw[X]=++cnt;\n\tst[++tp]=X;\n\tfor(int i=g[X];i;i=e[i].nxt){\n\t\tif(!dfn[e[i].v]){\n\t\t\tdfs0(e[i].v);lw[X]=Min(lw[X],lw[e[i].v]);\n\t\t}else if(vis[e[i].v]){\n\t\t\tlw[X]=Min(lw[X],dfn[e[i].v]);\n\t\t}\n\t}\n\tif(dfn[X]==lw[X]){\n\t\t++ccnt;\n\t\twhile(st[tp+1]!=X){\n\t\t\tclr[st[tp]]=ccnt;\n\t\t\tval[ccnt]+=v[st[tp]],ww[ccnt]+=w[st[tp]];\n\t\t\tvis[st[tp]]=0;\n\t\t\t--tp;\n\t\t}\n\t}\n}\ninline void dfs1(int X){\n\tfor(int i=ww[X];i&lt;=m;++i){\n\t\tf[X][i]=val[X];\n\t}\n\tfor(int i=h[X];i;i=e[i].nxt){\n\t\tdfs1(e[i].v);\n\t\tfor(int j=m-ww[X];j>=0;--j){\/\/j\u8868\u793a\u4e4b\u524d\u7684\u5b50\u6811\u7684\u91cd\u91cf\u548c\u3002 \n\t\t\tfor(int k=0;k&lt;=j;++k){\/\/k\u8868\u793a\u8fd9\u68f5\u5b50\u6811\u7684\u91cd\u91cf\u548c\u3002 \n\t\t\t\tf[X][j+ww[X]]=Max(f[X][j+ww[X]],f[e[i].v][k]+f[X][j-k+ww[X]]); \n\t\t\t}\n\t\t}\n\t}\n}\nvoid init(){\n\tscanf(\"%d%d\",&amp;n,&amp;m);\n\tfor(int i=1;i&lt;=n;++i){\n\t\tscanf(\"%d\",&amp;w[i]);\n\t}\n\tfor(int i=1;i&lt;=n;++i){\n\t\tscanf(\"%d\",&amp;v[i]);\n\t}\n\tfor(int i=1;i&lt;=n;++i){\n\t\tscanf(\"%d\",&amp;d[i]);\n\t\tif(d[i]){\n\t\t\tadd(g,d[i],i);\n\t\t}\n\t}\n\tfor(int i=1;i&lt;=n;++i){\n\t\tif(!dfn[i]){\n\t\t\tdfs0(i);\n\t\t}\n\t}\n\tfor(int i=1;i&lt;=n;++i){\n\t\tif(clr[d[i]]!=clr[i]){\n\t\t\tadd(h,clr[d[i]],clr[i]);\n\t\t\t++in[clr[i]];\n\t\t}\n\t}\n\tfor(int i=1;i&lt;=ccnt;++i){\n\t\tif(!in[i]){\n\t\t\tadd(h,0,i);\n\t\t}\n\t}\n\tdfs1(0);\n\tprintf(\"%d\\n\",f[0][m]);\n}\nint main(){\n\tinit();\n\treturn 0;\n}\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u7684tarjan\u7f29\u70b9+\u6811\u5f62\u80cc\u5305DP\u3002 \u8003\u8651N&lt;=100\uff0cM&lt;=500\uff0c\u53ea\u9700\u8981\u8bbef[i][j]\u8868\u793a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2019\/08\/08\/lp2515-haoi2010-%e8%bd%af%e4%bb%b6%e5%ae%89%e8%a3%85\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp2515 HAOI2010 \u8f6f\u4ef6\u5b89\u88c5\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[112,34,37,30,51,56,6],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/900"}],"collection":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/comments?post=900"}],"version-history":[{"count":1,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/900\/revisions"}],"predecessor-version":[{"id":903,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/900\/revisions\/903"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=900"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}