第一次接触这样的题,
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
//freopen("C://i.txt","r",stdin);
#define N 301
int n,m,k;
bool map[N][N];
int vist[N];
int y[N];
bool SearchPath(int x)
{
int i;
for (i=0;i<m;i++) if (!vist[i])
{
if (map[x][i])
{
vist[i]=true;
if (y[i]==-1||SearchPath(y[i]))
{
y[i]=x;
return true;
}
}
}
return false;
}
int MaxMatch()
{
int i;
int ans=0;
memset(y,-1,sizeof(y));
for (i=1;i<n;i++)
{
memset(vist,false,sizeof(vist));
if (SearchPath(i))
{
ans++;
}
}
return ans;
}
int main()
{
freopen("C://i.txt","r",stdin);
int i,j;
while (cin>>n,n)
{
cin>>m>>k;
memset(map,false,sizeof(map));
while (k--)
{
int a,b,c;
cin>>a>>b>>c;
if (b&&c)
map[b][c]=true;
}
cout<<MaxMatch()<<endl;
}
}
Language: Machine Schedule Description As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem. Input The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i, x, y. Output The output should be one integer per line, which means the minimal times of restarting machine. Sample Input 5 5 100 1 11 1 22 1 33 1 44 2 15 2 26 2 37 2 48 3 39 4 30 Sample Output 3 Source |
Time Limit: 1000MS | | Memory Limit: 10000K |
Total Submissions: 9049 | | Accepted: 3856 |