Escape(匈牙利算法变形)

Link:http://acm.hdu.edu.cn/showproblem.php?pid=3605


Problem:

Escape

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5145    Accepted Submission(s): 1346


Problem Description
2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets.
 

Input
More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
0 <= ai <= 100000
 

Output
Determine whether all people can live up to these stars
If you can output YES, otherwise output NO.
 

Sample Input
  
  
1 1 1 1 2 2 1 0 1 0 1 1
 

Sample Output
  
  
YES NO
 


#include<iostream>  
#include<cstdio>  
#include<list>  
#include<algorithm>  
#include<cstring>  
#include<string>  
#include<queue>  
#include<stack>  
#include<map>  
#include<vector>  
#include<cmath>  
#include<memory.h>  
#include<set>  
   
#define ll long long  
#define LL __int64  
#define eps 1e-8  
const ll INF=9999999999999;  
   
using namespace std;  
   
#define M 400000100  
   
#define inf 0xfffffff  
   
//vector<pair<int,int> > G;  
//typedef pair<int,int> P;  
//vector<pair<int,int>> ::iterator iter;  
//  
//map<ll,int>mp;  
//map<ll,int>::iterator p;  
   
//vector<int>G[8000];  
   
int mp[100012][22];  
int num[22];  
int marry[22];  
bool vis[22];  
int tempmp[22][100012];  
   
int dis[2][4]={0,-1,0,1,1,0,-1,0};  
   
int n,m,k;  
   
void clear()  
{  
    memset(tempmp,0,sizeof(tempmp));  
    memset(marry,0,sizeof(marry));  
    memset(num,0,sizeof(num));  
    memset(vis,false,sizeof(vis));  
    memset(mp,0,sizeof(mp));  
    /*for(int i=0;i<=n;i++) 
        G[i].clear();*/ 
}  
   
bool dfs(int x)  
{  
    for(int i=0;i<m;i++)  
    {  
        if(mp[x][i] && !vis[i])  
        {  
            vis[i]=true;  
            if(marry[i]<num[i])//这里的标记数组不一样了,不是之前的简单以为就能解决的,要是一个二维的,而且要遵循星球所住人数有限的限定  
            {  
                tempmp[i][marry[i]++]=x;//这里的marry数组跟以前意义大不一样,marry[i]=j,就是i跟左集合中的点匹配了j次  
                return 1;  
            }  
            for(int j=0;j<marry[i];j++)//比如marry[i]=j,要在i与各个点匹配中去寻找,  
            {  
                if(dfs(tempmp[i][j]))  //给tempmp[i][j]找新的星球 
                {  
                    tempmp[i][j]=x;  
                    return 1;  
                }  
            }  
        }  
    }  
    return 0;  
}  
   
int main(void)  
{  
    while(cin>>n>>m)  
    {  
        clear();  
        for(int i=0;i<n;i++)  
        {  
            for(int j=0;j<m;j++)  
            {  
                scanf("%d",&mp[i][j]);  
            }  
        }  
        for(int i=0;i<m;i++)  
            scanf("%d",&num[i]);//因为星球住的人数有限所以要设一个数组来限制  
        int ans=0;  
        for(int i=0;i<n;i++)  
        {  
            memset(vis,false,sizeof(vis));  
            if(!dfs(i))  
            {  
                ans=1;//本来这里用的是常用的ans++,如果ans==n就输出YES,不然就输出NO,可是那样超时了,现在直接标记,有出现不可匹配的直接输出NO,这样就过了,我觉得是题目数据有问题  
                break;  
            }  
        }  
        if(ans)  
            puts("NO");  
        else 
            puts("YES");  
    }  
} 


Redis下载、安装配置的教程如下: 1. 首先,您需要下载Redis的压缩包。您可以在官方网站或者其他可信的源获取到Redis的压缩包。在这个例子中,我们下载了一个名为redis-5.0.5.tar.gz的压缩包。 2. 将下载好的压缩包传送到您的Linux服务器上。您可以使用FTP工具(如FlashFXP)将压缩包上传到服务器中。 3. 在服务器上解压缩Redis压缩包。使用以下命令进行解压缩:tar -zxvf redis-5.0.5.tar.gz。 4. 确保您的服务器上安装了gcc编译器。您可以使用gcc -v命令来查看gcc的本。如果您的gcc本已经是4.8.5或更高本,那么您可以跳过这一步,直接执行make命令。 5. 进入Redis解压缩后的目录,在该目录下执行make命令来编译Redis。 6. 完成编译后,执行make install命令来安装Redis。 7. 确认Redis安装成功。您可以执行make install命令来确认Redis的安装情况。 8. 配置Redis服务端。进入Redis的bin目录,并通过指定的配置文件来启动Redis服务。例如,使用以下命令启动Redis服务端:redis-server myredis-config/redis.conf。 9. 启动Redis客户端。在Redis的bin目录下,使用redis-cli命令来启动Redis客户端。例如,使用以下命令启动Redis客户端:redis-cli -p 6379。 10. 如果您的Redis设置了密码,您需要在发送信息之前进行身份验证。使用auth命令来进行身份验证。例如,如果密码是"123456",可以使用以下命令进行身份验证:auth "123456"。 以上就是Redis下载、安装配置的基本教程。请根据您的需求服务器环境进行相应的配置操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值