• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 43,  comments - 9,  trackbacks - 0
            http://acm.hdu.edu.cn/showproblem.php?pid=3311

            給定6個(gè)基礎(chǔ)點(diǎn),和1000個(gè)輔助點(diǎn),以及無(wú)向邊若干。
            求一棵代價(jià)最小的生成子樹(shù),使得6個(gè)基礎(chǔ)點(diǎn)連通。
            http://en.wikipedia.org/wiki/Steiner_tree_problem

            方法一:
            狀態(tài)DP。
            一棵樹(shù),實(shí)際上可以看成是由兩棵子樹(shù)拼接而成,或者一棵樹(shù)擴(kuò)展一條邊篩選。而要完整地表示一棵子樹(shù),需要記錄它的根,和對(duì)6個(gè)基礎(chǔ)點(diǎn)的覆蓋狀態(tài)。
            這樣求一棵大樹(shù),可以枚舉接合點(diǎn),以及兩個(gè)子樹(shù)的覆蓋狀態(tài)。
            若dp[i][j],i表示接合點(diǎn),j表示覆蓋狀態(tài),那么dp[i][j]=min{dp[i][k]+dp[i][j^k]}。
            直接擴(kuò)展一條邊, 可以在保持j不變的情況下, 優(yōu)先隊(duì)列廣搜, 大大降低復(fù)雜度.

            方法二:
            spfa。
            dp[i][j]意義同上。一個(gè)點(diǎn)(i,j),對(duì)每個(gè)鄰接點(diǎn)i',枚舉那一頭的狀態(tài)j',然后用dp[i][j]+dp[i'][j']+way[i][i']去更新dp[i][j|j']和dp[i'][j|j']。

            ps. topcoder srm 470 div1 level3是此題升級(jí)版.

            ??1?#include?<string>
            ??2?#include?<vector>
            ??3?#include?<list>
            ??4?#include?<map>
            ??5?#include?<queue>
            ??6?#include?<stack>
            ??7?#include?<set>
            ??8?#include?<iostream>
            ??9?#include?<sstream>
            ?10?#include?<numeric>
            ?11?#include?<algorithm>
            ?12?#include?<cmath>
            ?13?#include?<cctype>
            ?14?#include?<cstdlib>
            ?15?#include?<cstdio>
            ?16?#include?<cstring>
            ?17?using?namespace?std;
            ?18?
            ?19?#define?CLR(x)?memset((x),0,sizeof(x))
            ?20?#define?SET(x,y)?memset((x),(y),sizeof(x))
            ?21?#define?REP(i,x)?for(int?i=0;i<(x);i++)
            ?22?#define?FOR(i,x,y)?for(int?i=(x);i<(y);i++)
            ?23?#define?VI?vector<int>?
            ?24?#define?PB(i,x)?(i).push_back(x)
            ?25?#define?MP(x,y)?make_pair((x),(y))
            ?26?
            ?27?struct?EDGE{
            ?28?????int?v,e,d;
            ?29?}edg[20000];
            ?30?int?ecnt,?gg[1006];
            ?31?
            ?32?struct?HEAP{
            ?33?????int?v,d;
            ?34?????void?set(int?nv,?int?nd){v=nv;d=nd;}
            ?35?}hp[1006*(1<<6)*10];
            ?36?int?sz;
            ?37?bool?vis[1006];
            ?38?
            ?39?int?dp[1006][1<<6];
            ?40?int?N,?M,?P;
            ?41?
            ?42?bool?cmp(const?HEAP?&a,?const?HEAP?&b)
            ?43?{?return?a.d>b.d;?}
            ?44?
            ?45?void?addedge(int?u,?int?v,?int?d)
            ?46?{
            ?47?????edg[ecnt].v=v;?edg[ecnt].d=d;?edg[ecnt].e=gg[u];?gg[u]=ecnt++;
            ?48?????edg[ecnt].v=u;?edg[ecnt].d=d;?edg[ecnt].e=gg[v];?gg[v]=ecnt++;
            ?49?}
            ?50?
            ?51?int?steiner()
            ?52?{
            ?53?????int?up?=?1<<(N+1);
            ?54?????SET(dp,-1);
            ?55?????REP(i,N+1)?dp[i][1<<i]=0;
            ?56?????FOR(i,N+1,N+M+1)?dp[i][0]=0;
            ?57?????REP(i,up){
            ?58?????????REP(j,N+M+1){
            ?59?????????????for(int?k=i;?k>0;?k=(k-1)&i){
            ?60?????????????????if(dp[j][k]!=-1?&&?dp[j][i^k]!=-1)
            ?61?????????????????????if(dp[j][i]==-1?||?dp[j][i]>dp[j][k]+dp[j][i^k])
            ?62?????????????????????????dp[j][i]=dp[j][k]+dp[j][i^k];
            ?63?????????????}
            ?64?????????}
            ?65?????????sz=0;
            ?66?????????CLR(vis);
            ?67?????????REP(j,N+M+1)?if(dp[j][i]!=-1){
            ?68?????????????hp[sz++].set(j,dp[j][i]);
            ?69?????????????push_heap(hp,?hp+sz,?cmp);
            ?70?????????}
            ?71?????????while(sz){
            ?72?????????????int?now=hp[0].v;
            ?73?????????????pop_heap(hp,?hp+sz--,cmp);
            ?74?????????????if(vis[now])continue;
            ?75?????????????vis[now]=true;
            ?76?????????????for(int?e=gg[now];?~e;?e=edg[e].e){
            ?77?????????????????int?to=edg[e].v,?td=dp[now][i]+edg[e].d;
            ?78?????????????????if(dp[to][i]==-1?||?dp[to][i]>td){
            ?79?????????????????????dp[to][i]=td;
            ?80?????????????????????hp[sz++].set(to,td);
            ?81?????????????????????push_heap(hp,?hp+sz,?cmp);
            ?82?????????????????}
            ?83?????????????}
            ?84?????????}
            ?85?????}
            ?86?????return?dp[0][up-1];
            ?87?}
            ?88?
            ?89?int?main()
            ?90?{
            ?91?????while(~scanf("%d?%d?%d",?&N,?&M,?&P)){
            ?92?????????int?u,?v,?d;
            ?93?????????SET(gg,-1);?ecnt=0;
            ?94?????????REP(i,N+M){
            ?95?????????????scanf("%d",?&d);
            ?96?????????????addedge(0,i+1,?d);
            ?97?????????}
            ?98?????????REP(i,P){
            ?99?????????????scanf("%d?%d?%d",?&u,?&v,?&d);
            100?????????????addedge(u,v,d);
            101?????????}
            102?????????int?ret=steiner();
            103?????????printf("%d\n",?ret);
            104?????}
            105?????return?0;
            106?}

            posted on 2010-05-27 16:21 wolf5x 閱讀(599) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): acm_icpc
            <2009年6月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            "Do not spend all your time on training or studying - this way you will probably become very exhausted and unwilling to compete more. Whatever you do - have fun. Once you find programming is no fun anymore – drop it. Play soccer, find a girlfriend, study something not related to programming, just live a life - programming contests are only programming contests, and nothing more. Don't let them become your life - for your life is much more interesting and colorful." -- Petr

            留言簿(3)

            隨筆分類(lèi)(59)

            隨筆檔案(43)

            cows

            搜索

            •  

            最新評(píng)論

            評(píng)論排行榜

            a级毛片无码兔费真人久久| 少妇人妻88久久中文字幕| 久久天天躁狠狠躁夜夜2020| 久久综合九色综合欧美狠狠| 久久国产一片免费观看| 青青热久久国产久精品| 日韩乱码人妻无码中文字幕久久 | 青青青青久久精品国产| 久久成人18免费网站| 久久久久人妻一区精品性色av| 99久久精品国产毛片| 亚洲∧v久久久无码精品| 亚洲精品高清国产一久久| 中文字幕乱码久久午夜| 久久国产影院| 国产精品久久久99| 99久久精品午夜一区二区| 国内精品久久久久影院老司| 日本久久久精品中文字幕| 亚洲精品乱码久久久久久久久久久久| 99久久无码一区人妻| av国内精品久久久久影院| 婷婷久久香蕉五月综合加勒比| 一本一本久久a久久精品综合麻豆| 久久精品国产精品青草| 亚洲精品美女久久777777| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 人妻无码αv中文字幕久久琪琪布| 欧美久久一区二区三区| 国内精品久久久久久久久| 久久久青草久久久青草| 国产精品一久久香蕉国产线看观看| 久久99热这里只频精品6| 亚洲国产精品一区二区三区久久| 久久国产美女免费观看精品 | 久久午夜电影网| 国产巨作麻豆欧美亚洲综合久久| 99久久无码一区人妻| 久久香蕉国产线看观看猫咪?v| 欧美激情精品久久久久久| 香蕉aa三级久久毛片|