First preprocessing out the first k points between each other the shortest, direct Dijkstra is good
Then it becomes a pressure dp ... Just write it, please.
1 /**************************************************************2 problem:10973 User:rausen4 language:c++5 result:accepted6 time:18456 Ms7 memory:98872 KB8 ****************************************************************/9 Ten#include <cstdio> One#include <cstring> A#include <algorithm> -#include <queue> - the using namespacestd; - Const intN = 2e4 +5; - Const intM = 2e5 +5; - Const intK = A; + Const inttot_s =1<< -; - Const intINF =1e9; + A structEdge { at intNext, to, V; -Edgeint_n =0,int_t =0,int_v =0): Next (_n), to (_t), V (_v) {} -} e[m <<1]; - - structHeap_node { - intV, to; inHeap_node (int_v =0,int_t =0): V (_v), to (_t) {} - toInlineBOOL operator< (ConstHeap_node &p)Const { + returnV >p.v; - } the }; * $ intN, M, K, ans;Panax Notoginseng intfirst[n], tot; - intBin[k], a[k]; the intDis[k][k], d[n]; + intS, S1; A intF[tot_s][k]; thePriority_queue h; + -InlineintRead () { $ Static intx; $ Static Charch; -x =0, ch =GetChar (); - while(Ch <'0'||'9'<ch) theCH =GetChar (); - while('0'<= CH && Ch <='9') {Wuyix = x *Ten+ CH-'0'; theCH =GetChar (); - } Wu returnx; - } About $InlinevoidAdd_edges (intXintYintz) { -E[++tot] = Edge (first[x], y, z), first[x] =tot; -E[++tot] = Edge (First[y], x, z), first[y] =tot; - } A +InlinevoidAdd_to_heap (intp) { the Static intx; - for(x = first[p]; x; x =e[x].next) $ if(D[e[x].to] = =-1) theH.push (Heap_node (E[X].V +D[p], e[x].to)); the } the the voidDijkstra (intS) { - Static intp; inmemset (D,-1,sizeof(d)); the while(!h.empty ()) H.pop (); theD[s] =0, Add_to_heap (S); About while(!H.empty ()) { the if(D[h.top (). to]! =-1) { the H.pop (); the Continue; + } -p =H.top (). to; theD[P] =h.top (). V;Bayi H.pop (); the add_to_heap (p); the } - } - the intMain () { the intI, J, X, Y, Z; then = Read (), M = Read (), k =read (); the for(i =1; I <= m; ++i) { -x = Read (), y = read (), z =read (); the add_edges (x, y, z); the } the for(i =1; I <= K +1; ++i) {94 Dijkstra (i); the for(dis[i][0] = D[n], j =1; J <= K +1; ++j) theDIS[I][J] =D[j]; the }98 for(i = bin[0] =1; I <= K +1; ++i) Bin[i] = bin[i-1] <<1; About for(x = Read (), i =1; I <= x; ++i) -y = read (), z = Read (), a[z] + = bin[y-2];101 102Memset (F,0x3f,sizeof(f));103 for(S = f[0][1] =0; S < bin[k]; ++S)104 for(i =1; I <= K +1; ++i)if(F[s][i]! =0x3f3f3f3f) the for(j =2; J <= K +1; ++j) {106S1 = S | Bin[j-2];107 if((S & a[j]) = = A[j]) f[s1][j] = min (F[s1][j], F[s][i] +dis[i][j]);108 }109 for(ans = inf, i =1; I <= K +1; ++i) theans = min (ans, f[bin[k)-1][i] + dis[i][0]);111printf"%d\n", ans); the return 0;113}
View Code
BZOJ1097 [POI2007] Tourist Attractions ATR