Make the Team(匈牙利算法)

Make the Team

时间限制:C/C++ 5秒,其他语言10秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述 

You are eager to make the programming team. You have decided that if you watch several videos,
you will increase your chances of making the team. Each video you want to watch is one hour
long, and each video plays at specific times. Naturally, you want to get through all the videos as
fast as possible, to leave more time to practice!
For example, if you want to watch two videos and the first one is available at the time intervals
[1,2), [4,5), [8,9) and [12,13), and the second video is available at the time intervals [4,5), [7,8),
and [11,12), then the earliest time at which you can complete the two videos is time 5. You can
accomplish this by watching the first video in the time interval [1,2) and the second one at the time
interval [4,5). Note that all videos play for precisely the length of one time interval, and one can
watch back to back videos. Thus, if one video plays at the interval [x, x+1) and another video

plays at the interval [x+1, x+2), where x is a positive integer, both can be watched, back to back.

Given a list of times that each video you want to watch is available, determine the earliest time at
which you can complete watching all of the videos. Note that the videos can be watched in any
order as long as the time intervals allow. 
 

输入描述:

The first input line contains a single integer,n(1 ≤n≤ 200), indicating the number of videos you
would like to watch. Each of the nextninput lines describes a video you want to watch. Theith
of these input lines starts with an integer,ti(1 ≤ti≤ 30), representing the number of times videoi
is available to watch. This is followed bytispace separated values indicating the starting time
videoiis available to watch. The list of times for each video will be a strictly increasing list of
positive integers, with a maximum value of 1000. It is guaranteed that there will be at least one
arrangement that allows you to watch all of the videos.

输出描述:

Print the earliest time at which you can complete watching all of the videos.

示例1

输入

复制

3
2 4 6
3 4 9 11
1 4

输出

复制

10

示例2

输入

复制

4
2 3 11
3 2 9 11
2 2 3
2 3 9

输出

复制

12
#include<iostream>
#include<vector>

using namespace std;
const int maxn=10010;
int vis[maxn];
int M[maxn];
vector<int> f[maxn];
int n,m;
int x;
int dfs(int x){
    for(int i=0;i<f[x].size();i++){
        if(!vis[f[x][i]]){
            vis[f[x][i]]=1;
            if(!M[f[x][i]]||dfs(M[f[x][i]])){
                M[f[x][i]]=x;
                return 1;
            }
        }
    }
               return 0;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>m;
        for(int j=1;j<=m;j++){
            cin>>x;
            f[x+1].push_back(i);
        }
    }
    int res=0;
    
    for(int i=1;i<=1001;i++){
        memset(vis, 0, sizeof(vis));
        if(dfs(i)) {
            res=i;
        }
    }
    cout<<res;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郭晋龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值