• <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>

            zoj3620

            Escape Time II

            Time Limit: 2 Seconds      Memory Limit: 65536 KB

            There is a fire in LTR ’ s home again. The fire can destroy all the things in t seconds, so LTR has to escape in t seconds. But there are some jewels in LTR ’ s rooms, LTR love jewels very much so he wants to take his jewels as many as possible before he goes to the exit. Assume that the ith room has ji jewels. At the beginning LTR is in room s, and the exit is in room e.

            Your job is to find a way that LTR can go to the exit in time and take his jewels as many as possible.

            Input

            There are multiple test cases.
            For each test case:
            The 1st line contains 3 integers n (2 ≤ n ≤ 10), m, t (1 ≤ t ≤ 1000000) indicating the number of rooms, the number of edges between rooms and the escape time.
            The 2nd line contains 2 integers s and e, indicating the starting room and the exit.
            The 3rd line contains n integers, the ith interger ji (1 ≤ ji ≤ 1000000) indicating the number of jewels in the ith room.
            The next m lines, every line contains 3 integers a, b, c, indicating that there is a way between room a and room b and it will take c (1 ≤ ct) seconds.

            Output

            For each test cases, you should print one line contains one integer the maximum number of jewels that LTR can take. If LTR can not reach the exit in time then output 0 instead.

            Sample Input

            3 3 5 0 2 10 10 10 0 1 1  0 2 2 1 2 3 5 7 9 0 3 10 20 20 30 20 0 1 2 1 3 5 0 3 3 2 3 2 1 2 5 1 4 4 3 4 2

            Sample Output

            30 80

            Author: FU, Yujun
            Contest: ZOJ Monthly, June 2012

            狀態(tài)搜索,
            搜索寫了不少,但是以前幾乎沒寫過這一類的題目,
            要開始練搜索啊

            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            #define maxn 15
            #define inf 1000000000
            using namespace std;
            int mp[maxn][maxn];
            int t,n,m,s,e,ti,x,y;
            int a[maxn];
            long long ans;
            struct node
            {
                
            int v,st,val,ti;
            } tmp,tmp1;
            queue
            <node> q;
            int head,tail;
            int get[15][1024];
            int mt[15][1024];
            int max(int a,int b)
            {
                
            return a>b?a:b;
            }
            int main()
            {
                
            int res;
                
            while(scanf("%d%d%d",&n,&m,&t)!=EOF)
                {
                    scanf(
            "%d%d",&s,&e);
                    
            for(int i=0; i<n; i++) scanf("%d",&a[i]);
                    
            for(int i=0; i<n; i++)
                    {
                        
            for(int j=i+1; j<n; j++)
                            mp[i][j]
            =mp[j][i]=inf;
                    }
                    
            for(int i=1; i<=m; i++)
                    {
                        scanf(
            "%d%d%d",&x,&y,&ti);
                        
            if(ti<mp[x][y])
                        {
                            mp[x][y]
            =ti;
                            mp[y][x]
            =ti;
                        }
                    }
                    memset(
            get,0,sizeof(get));//這地方老是順手寫成sizeof(0)
                    for(int i=0; i<n; i++)
                    {
                        
            for(int j=0; j<(1<<n); j++)
                        {
                            mt[i][j]
            =inf;
                        }
                    }
                    
            get[s][1<<s]=a[s];
                    mt[s][
            1<<s]=0;
                    res
            =0;
                    tmp.v
            =s;
                    tmp.ti
            =0;
                    tmp.val
            =a[s];
                    tmp.st
            =1<<s;
                    q.push(tmp);
                    
            while(!q.empty())
                    {
                        tmp
            =q.front();
                        q.pop();
                        
            for(int i=0; i<n; i++)
                        {
                            
            if(i==tmp.v) continue;
                            
            if(mp[tmp.v][i]+tmp.ti<=t)
                            {
                                tmp1.val
            =tmp.val;
                                tmp1.st
            =tmp.st;
                                
            if(!((tmp1.st>>i)&1))
                                {
                                    tmp1.st
            =tmp1.st|(1<<i);
                                    tmp1.val
            +=a[i];
                                }
                                
            if(tmp1.val>get[i][tmp1.st]||(tmp1.val==get[i][tmp1.st]&&tmp.ti+mp[tmp.v][i]<mt[i][tmp1.st]))
                                {
                                    
            get[i][tmp1.st]=tmp1.val;
                                    mt[i][tmp1.st]
            =tmp.ti+mp[tmp.v][i];
                                    tmp1.ti
            =mt[i][tmp1.st];
                                    tmp1.v
            =i;
                                    q.push(tmp1);
                                }
                            }
                        }
                    }
                    
            for(int i=0; i<(1<<n); i++)
                        res
            =max(get[e][i],res);
                    printf(
            "%d\n",res);
                }
                
            return 0;
            }

            posted on 2012-07-30 21:51 jh818012 閱讀(96) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標(biāo)題查看
            • --王私江
            久久久亚洲欧洲日产国码二区| 久久精品亚洲中文字幕无码麻豆| 99久久亚洲综合精品网站| 韩国三级大全久久网站| 久久久久免费视频| 久久精品aⅴ无码中文字字幕不卡| 中文字幕亚洲综合久久| 久久99久国产麻精品66| 久久r热这里有精品视频| 中文字幕精品无码久久久久久3D日动漫 | 香蕉久久夜色精品国产小说| 久久露脸国产精品| 国产精品久久久福利| 久久AV高潮AV无码AV| 老司机午夜网站国内精品久久久久久久久| 精产国品久久一二三产区区别| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 久久久久久免费一区二区三区| 青青久久精品国产免费看| 久久夜色精品国产噜噜麻豆| 亚洲精品无码久久久| 一本一道久久精品综合| 激情伊人五月天久久综合| 久久久久久久波多野结衣高潮| 狠狠色综合网站久久久久久久| 久久精品水蜜桃av综合天堂| 日产久久强奸免费的看| 2020最新久久久视精品爱| 国内精品伊人久久久久| 国产精品国色综合久久| 久久精品亚洲一区二区三区浴池 | 国产精品一久久香蕉国产线看| 五月丁香综合激情六月久久| 综合久久一区二区三区| 久久综合偷偷噜噜噜色| 亚洲AV伊人久久青青草原| 久久无码人妻精品一区二区三区| 久久国产成人精品国产成人亚洲| 国产AV影片久久久久久| 久久久久久久亚洲精品| 一本色综合久久|