• <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>
            隨筆 - 97, 文章 - 22, 評論 - 81, 引用 - 0
            數(shù)據(jù)加載中……

            Pku 1632 Vase Collection (Dfs)

            問題描述:
            給定一些關系,是個二分圖,要求它的最大完美匹配。
            解題思路:
            枚舉左邊的點,對任意一個點枚舉它的邊子集,再在枚舉到的邊子集的右邊點集中以相同方式枚舉,最后形成左右兩邊均為K的點,檢測是否為完全二分圖即可。

            代碼如下:
            #include <iostream>
            #include 
            <vector>
            using namespace std;

            int t;
            int n, i;

            vector 
            < int > lvec[40], rvec[40];
            int l, r, dep;
            int bo[40], Max;

            struct Stack
            {
                
            int a[100];
                
            int top;
            }
            Left, Right;

            int map[40][40];


            //檢查給定圖是否是K-完美匹配圖(這里K == Left.top)
            int Process()
            {
                
            int i, j;
                
            //Stack Left
                
            //Stack Right
                
            //檢查兩個棧中是否有完全邊,即K*K條邊

                
            for(i = 0; i < Left.top; i++)
                
            {
                    
            for(j = 0; j < Right.top; j++)
                    
            {
                        
            if(!map[ Right.a[j] ][ Left.a[i] ])
                            
            return 0;
                    }

                }


                
            return 1;
            }



            //對右邊的第一個被左邊點枚舉到的點進行枚舉,枚舉它的邊子集
            int rdfs(int u, int index)
            {
                
            int i, size = rvec[u].size();

                
            if(size < Left.top)
                    
            return 0;

                
            if(Right.top > Left.top)
                    
            return 0;

                
            if(Left.top == Right.top)
                
            {
                    
            if( Process() )
                        
            return 1;
                }


                
            for(i = index; i < size; i++){
                    Right.a[ Right.top
            ++ ] = rvec[u][i];
                    
            if( rdfs(u, i+1) )
                        
            return 1;
                    Right.top 
            --;
                }

                
            return 0;
            }


            //左邊任選一個點枚舉他的邊子集

            void ldfs(int u, int index)
            {
                
            int i, size = lvec[u].size();

                
            if(Left.top > 10)
                    
            return ;

                Right.top 
            = 0;


                
            if(Left.top > Max && rdfs(Left.a[0], 0) )
                
            {
                    
            if(Left.top > Max)
                        Max 
            =  Left.top;
                }


                
            for(i = index; i < size; i++){
                    Left.a[ Left.top
            ++ ] = lvec[u][i];
                    ldfs(u, i
            +1);
                    Left.top 
            --;
                }

            }


            int main()
            {
                
            int i, j;
                scanf(
            "%d"&t);

                
            while(t--)
                
            {
                    Max 
            = 0;
                    scanf(
            "%d"&n);

                    memset(map, 
            0sizeof(map));

                    
            for(i = 1; i <= 36; i++)
                    
            {
                        lvec[i].clear();
                        rvec[i].clear();
                    }


                    memset( bo, 
            0sizeof(bo) );

                    
            for(i = 0; i < n; i++)
                    
            {
                        scanf(
            "%d %d"&l, &r);
                        map[l][r] 
            = 1;
                        bo[ l ] 
            = 1;
                    }


                    
            for(i = 1; i <= 36; i++){

                        
            for(j = 1; j <= 36; j++){

                            
            if(map[i][j])
                            
            {
                                lvec[i].push_back( j );
                                rvec[j].push_back( i );
                            }

                        }

                    }


                    
            for(i = 1; i <= 36; i++)
                    
            {
                        
            if(bo[i]){
                            Left.top 
            = 0;
                            ldfs(i, 
            0);
                        }

                    }

                    printf(
            "%d\n", Max);
                }

            }

            posted on 2009-02-15 21:15 英雄哪里出來 閱讀(415) 評論(0)  編輯 收藏 引用 所屬分類: ACM

            亚洲国产日韩欧美久久| 久久青青草原精品影院| 亚洲国产精品成人AV无码久久综合影院| 国产精品丝袜久久久久久不卡| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 99久久夜色精品国产网站| 欧美黑人又粗又大久久久| 久久97久久97精品免视看| 国产毛片欧美毛片久久久| 青青国产成人久久91网| 久久亚洲AV无码精品色午夜| 国产产无码乱码精品久久鸭| 久久亚洲国产成人影院| 99国产精品久久| 亚洲精品午夜国产VA久久成人| 国产亚洲美女精品久久久| 色欲久久久天天天综合网| 久久精品国产一区二区电影| 精品久久久久久中文字幕人妻最新| 国内精品伊人久久久久网站| www.久久热| 亚洲人成精品久久久久| 一本一道久久a久久精品综合| 久久久91精品国产一区二区三区 | 久久婷婷五月综合国产尤物app| 久久er99热精品一区二区| 久久精品aⅴ无码中文字字幕不卡 久久精品成人欧美大片 | 久久久久久久免费视频| 久久久久国产精品麻豆AR影院| 97精品久久天干天天天按摩| 久久精品人人做人人爽电影蜜月| 久久精品国产色蜜蜜麻豆| 香蕉久久永久视频| 亚洲精品久久久www| 亚洲伊人久久综合中文成人网| 久久久久久亚洲精品无码| 婷婷久久综合九色综合98| 久久精品国产一区二区三区日韩| 国内精品久久久人妻中文字幕| 久久国产色AV免费观看| 国产Av激情久久无码天堂|