• <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
            數據加載中……

            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 英雄哪里出來 閱讀(405) 評論(0)  編輯 收藏 引用 所屬分類: ACM

            久久最新免费视频| 国产精品久久久久久五月尺| 久久综合88熟人妻| 久久91精品国产91久久麻豆| 久久精品国产亚洲一区二区| 久久精品国产清自在天天线| 欧美日韩久久中文字幕| 99久久这里只有精品| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久久久国色AV免费看图片| 人妻中文久久久久| 亚洲精品高清国产一线久久| 午夜不卡888久久| 一本色道久久综合狠狠躁| 久久亚洲欧美日本精品| 奇米影视7777久久精品| 久久精品国产清自在天天线| 国产成年无码久久久久毛片| 久久精品青青草原伊人| 久久国产免费| 国产精品久久久久一区二区三区| 久久天天躁狠狠躁夜夜96流白浆| 欧美亚洲另类久久综合婷婷| 精品久久久久久99人妻| 秋霞久久国产精品电影院| 久久精品欧美日韩精品| 国内精品伊人久久久久777| 精品久久久久久99人妻| 国产成人99久久亚洲综合精品| 精品久久久久久亚洲精品| 亚洲综合伊人久久综合| 久久精品中文字幕大胸| 久久精品国产黑森林| 久久精品视频网| 精品999久久久久久中文字幕 | 国产精品视频久久久| 国内精品久久人妻互换| 久久国产精品久久| 国内精品久久久久久中文字幕 | 国产V亚洲V天堂无码久久久| 99久久精品国产高清一区二区|