{"id":302,"date":"2018-11-01T07:45:22","date_gmt":"2018-10-31T23:45:22","guid":{"rendered":"http:\/\/SmokeyDays.top\/wordpress\/?p=302"},"modified":"2018-11-07T16:35:07","modified_gmt":"2018-11-07T08:35:07","slug":"lp3953-noip2018-%e9%80%9b%e5%85%ac%e5%9b%ad","status":"publish","type":"post","link":"http:\/\/SmokeyDays.top\/wordpress\/2018\/11\/01\/lp3953-noip2018-%e9%80%9b%e5%85%ac%e5%9b%ad\/","title":{"rendered":"lp3953 NOIP2017 \u901b\u516c\u56ed"},"content":{"rendered":"<p>\u5bb9\u6613\u77e5\u9053\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u70b9\uff0c\u6700\u591a\u53ea\u80fd\u504f\u79fb50\u3002<br \/>\n\u7531\u6b64\u53ef\u4ee5\u8dd1\u8bb0\u5fc6\u5316\u641c\u7d22\uff1a\\(f_{i,j}\\)\u8868\u793a\uff0c\u5728\u7b2ci\u4e2a\u70b9\uff0c\u6bd4\u6700\u77ed\u8def\u957f\u4e86j\u65f6\u7684\u65b9\u6848\u6570\u3002<br \/>\n\u90a3\u4e48\uff0c\u6211\u4eec\u5012\u7740\u641c\u5373\u53ef\u3002<br \/>\n\u5177\u4f53\u6765\u8bf4\uff0c\u5b9a\u4e49\\(dn_{x}\\)\u8868\u793a\\(x-&gt;u\\)\u7684\u6700\u77ed\u8def\u3002<br \/>\n\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u72b6\u6001\u8f6c\u79fb\u65b9\u7a0b\uff1a<br \/>\n$$f_{u,k}=\\sum_{v,v\\in S,st: \\forall x \\in S,x_{u}=u}f_{v,k-dn_{v}+dn_{u}-w}$$<br \/>\n\u7b54\u6848\u4e3a\\(f_{1,K}\\)<br \/>\n\u51e0\u4e2a\u7ec6\u8282\uff1a<br \/>\ne[i].nxt\u4e0d\u5e94\u5199\u4f5ce[i].v<br \/>\n\u4e0d\u8981\u4f7f\u7528\u957f\u5f97\u5dee\u4e0d\u591a\u7684\u53d8\u91cf\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"cpp\">#include&lt;iostream&gt;\r\n#include&lt;cstdio&gt;\r\n#include&lt;queue&gt; \r\n#include&lt;cstring&gt;\r\nusing namespace std;\r\nstruct ee{\r\n    int v;\r\n    int w;\r\n    int nxt;\r\n}e[400005];\r\nint h[100005],h2[100005],et=0,n,m,K,p,dis[100005],dn[100005],f[100005][51];\r\nbool usd[100005][51];\r\ninline void add(int *_H,const int &amp;u,const int &amp;v,const int &amp;w){\r\n    e[++et]=(ee){v,w,_H[u]};\r\n    _H[u]=et;\r\n}\r\nstruct cmp2{\r\n    inline bool operator ()(const int &amp;X,const int &amp;Y)const{\r\n        return dn[X]&gt;dn[Y];\r\n    }\r\n};\r\nvoid dij2(){\r\n    priority_queue&lt; int,vector&lt;int&gt;,cmp2 &gt; q;\r\n    memset(dn,0x3f,sizeof(dn));\r\n    dn[n]=0;\r\n    q.push(n);\r\n    int nw;\r\n    while(!q.empty()){\r\n        nw=q.top();\r\n        q.pop();\r\n        for(int i=h2[nw];i;i=e[i].nxt){\r\n            if(dn[e[i].v]&gt;dn[nw]+e[i].w){\r\n                dn[e[i].v]=dn[nw]+e[i].w;\r\n                q.push(e[i].v);\r\n            }\r\n        }\r\n    }\r\n}\r\nint dfs(int u,int k){\r\n    if(usd[u][k]){\r\n        return -1;\r\n    }\r\n    if(f[u][k]){\r\n        return f[u][k];\r\n    }\r\n    usd[u][k]=1;\r\n    if(u==n){\r\n        f[u][k]=1;\r\n    }\r\n    int X,sm;\r\n    for(int i=h[u];i;i=e[i].nxt){\r\n        \/\/e[i].v\u4e0d\u80fd\u5199\u6210e[i].nxt \r\n        sm=dn[e[i].v]-dn[u]+e[i].w;\r\n        if(sm&gt;k){\r\n            continue;\r\n        }\r\n        X=dfs(e[i].v,k-sm);\r\n        if(X==-1){\r\n            return f[u][k]=-1;\r\n        }\r\n        f[u][k]+=X;\r\n        f[u][k]%=p;\r\n    }\r\n    usd[u][k]=0;\r\n    return f[u][k];\r\n}\r\nvoid init(){\r\n    memset(h,0,sizeof(h));\r\n    memset(h2,0,sizeof(h2));\r\n    scanf(\"%d%d%d%d\",&amp;n,&amp;m,&amp;K,&amp;p);\r\n    et=0;\r\n    int u,v,w;\r\n    for(int i=1;i&lt;=m;++i){\r\n        scanf(\"%d%d%d\",&amp;u,&amp;v,&amp;w);\r\n        add(h,u,v,w);\r\n        add(h2,v,u,w);\r\n    }\r\n    dij2();\r\n    memset(f,0,sizeof(f));\r\n    memset(usd,0,sizeof(usd));\r\n    printf(\"%d\\n\",dfs(1,K));\r\n}\r\nint main(){\r\n    int T;\r\n    scanf(\"%d\",&amp;T);\r\n    while(T--){\r\n        init();\r\n    }\r\n    return 0;\r\n}<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5bb9\u6613\u77e5\u9053\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u70b9\uff0c\u6700\u591a\u53ea\u80fd\u504f\u79fb50\u3002 \u7531\u6b64\u53ef\u4ee5\u8dd1\u8bb0\u5fc6\u5316\u641c\u7d22\uff1a\\(f_{i,j}\\)\u8868\u793a\uff0c\u5728\u7b2ci\u4e2a\u70b9\uff0c\u6bd4\u6700\u77ed &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/SmokeyDays.top\/wordpress\/2018\/11\/01\/lp3953-noip2018-%e9%80%9b%e5%85%ac%e5%9b%ad\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201clp3953 NOIP2017 \u901b\u516c\u56ed\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":[10,30,35,31,8,6,36,5],"tags":[],"_links":{"self":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/302"}],"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=302"}],"version-history":[{"count":5,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/302\/revisions"}],"predecessor-version":[{"id":360,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/posts\/302\/revisions\/360"}],"wp:attachment":[{"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/media?parent=302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/categories?post=302"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/SmokeyDays.top\/wordpress\/wp-json\/wp\/v2\/tags?post=302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}