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