zoukankan      html  css  js  c++  java
  • POJ_3342_Party_at_Hali-Bula

    #include <iostream>
    #include <map>
    #include <cstring>
    using namespace std;
    
    int Graph[210][210];
    int DP[210][2];
    int count;
    
    void DFS( int index ){
        DP[index][0] = 0;
        DP[index][1] = 1;
        for( int i = 1; i <= count; ++i ){
            if( Graph[index][i] ){
                DFS(i);
                DP[index][0] += max( DP[i][0], DP[i][1] );
                DP[index][1] += DP[i][0];
            }
        }
    }
    
    bool check(){
        for( int i = 1; i <= count; ++i ){
            if( DP[i][0] == DP[i][1] ){
                for( int j = 1; j <= count; ++j ){
                    if( Graph[i][j] == 1 && DP[j][0] == DP[j][1] ) return false;
                }
            }
        }
        return true;
    }
    
    int main(){
        while( true ){
            memset( Graph, 0, sizeof(Graph) );
            count = 1;
            map<string, int>mapTemp;
            int n;
            cin>>n;
            if( n == 0 ) break;
            string boss;
            cin>>boss;
            mapTemp[boss] = count++;
            for( int i = 2; i <= n; ++i ){
                string son;
                string parent;
                cin>>son>>parent;
                if( !mapTemp[son] ) mapTemp[son] = count++;
                if( !mapTemp[parent] ) mapTemp[parent] = count++;
                Graph[mapTemp[parent]][mapTemp[son]] = 1;
            }
            DFS(1);
            cout<<max(DP[1][0], DP[1][1])<<" ";
            if( n == 1 ){
                cout<<"Yes"<<endl;
                continue;
            }
            if( n == 2 ){
                cout<<"No"<<endl;
                continue;
            }
            if( check() ){
                cout<<"Yes"<<endl;
                continue;
            }
            if(!check()){
                cout<<"No"<<endl;
                continue;
            }
        }
        return 0;
    }
    


  • 相关阅读:
    python爬虫(二)_HTTP的请求和响应
    python迭代器
    矩阵快速幂
    hdu 2256 Problem of Precision
    牛客练习赛17 ABD
    hdu 1575 Tr A
    hdu 1757 矩阵快速幂
    51nod 1402最大值
    51nod 1393 0和1相等串
    勤奋的杨老师
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3400457.html
Copyright © 2011-2022 走看看