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;
    }
    


  • 相关阅读:
    叶落归根(hometown)
    设置(settings)
    文明距离(civil)
    计算机基础知识
    gojs插件使用教程
    编程语言分类
    dp优化简单总结
    Splay入门题目 [HNOI2002]营业额统计
    hdu3415:最大k子段和,单调队列
    hdu5072(鞍山regional problem C):容斥,同色三角形模型
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3400457.html
Copyright © 2011-2022 走看看