• poj 3281 Dining 夜


    http://poj.org/problem?id=3281

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <queue>
    #include <algorithm>
    using namespace std;

    const int MAX=0x7fffffff;
    const int N=510;
    int path[N][N];
    int l[N];
    int n,f,d;
    int Bfs()
    {
       memset(l,-1,sizeof(l));
       queue< int >str;
       str.push(0);
       int k;
       l[0]=0;
       while(!str.empty())
       {
           k=str.front();
           str.pop();
           for(int i=n;i>=0;--i)
           { if(path[k][i]>0&&l[i]==-1)
               {
                   l[i]=l[k]+1;
                   str.push(i);
               }
           }
       }
       //for(int i=0;i<=n;++i)
       //printf("( %d  %d ) ",i,l[i]);
       //cout<<endl;
       if(l[n]!=-1)
       return true;
       return false;
    }
    int Dfs(int x,int Max)
    {
        int sum=Max;
        if(x==n)
        {return Max;}
        for(int i=0;i<=n;++i)
        {
            if(sum==0)
            break;
            if(l[i]==l[x]+1&&path[x][i]>0)
            {
                int w=Dfs(i,min(sum,path[x][i]));
                path[x][i]-=w;
                path[i][x]+=w;
                sum-=w;
            }
        }
        return (Max-sum);
    }
    int main()
    {
        //freopen("data.txt","r",stdin);
        //while(1)
        {
        scanf("%d %d %d",&n,&f,&d);
        int k1,k2;
        int w;
        memset(path,0,sizeof(path));
        for(int i=1;i<=n;++i)
        {
            path[i][i+n]=1;
            scanf("%d %d",&k1,&k2);//cout<<i<<" "<<i+n<<endl;
            while(k1--)
            {
               scanf("%d",&w);
               path[w+2*n][i]=1;//cout<<w+2*n<<" "<<i<<endl;
               path[0][w+2*n]=1;
            }
            while(k2--)
            {
                scanf("%d",&w);
                path[i+n][w+2*n+f]=1;//cout<<i+n<<" "<<w+2*n+f<<endl;
                path[w+2*n+f][2*n+f+d+1]=1;
            }
        }
        n=2*n+f+d+1;//cout<<"n=== "<<n<<endl;
        int ans=0;
        while(Bfs())
        {
            while(1)
            {
                w=Dfs(0,MAX);
                if(w==0)
                break;
                ans+=w;
            }

        }
        printf("%d\n",ans);
        }
        return 0;
    }

  • 相关阅读:
    变量的作用域
    内联函数inline
    数组、函数和指针
    关于android:configChanges的属性的简介
    Android 更新UI的两种方法
    android开发两种退出程序方式
    google内购In-App Billing
    谷歌登陆sdk对接
    openssl测试版本小工具
    关于facebook登陆不安装openssl的情况下怎么获得Facebook Key Hash的简单方法
  • 原文地址:https://www.cnblogs.com/liulangye/p/2477655.html
Copyright © 2020-2023  润新知