题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1149
代码:
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
using namespace std;
int n, m;
int p[1000][1000];
int book[1000];
int match[1000];
int dfs(int u)
{
int i;
for (i = 1;i <= m;i++)
{
if (book[i] == 0 && p[u][i] == 1)
{
book[i] = 1;
if (match[i] == 0 || dfs(match[i]))
{
match[i] = u;
return 1;
}
}
}
return 0;
}
int a[110], b[110];
int main()
{
int t;
int cases = 1;
scanf("%d", &t);
while (t--)
{
scanf("%d",&n);
for (int i = 1;i <= n;i++) scanf("%d", &a[i]);
scanf("%d", &m);
for (int i = 1;i <= m;i++) scanf("%d", &b[i]);
int ans = 0;
memset(match, 0, sizeof(match));
memset(p, 0, sizeof(p));
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (b[j] % a[i] == 0) p[i][j] = 1;
for (int i = 1;i <= n;i++)
{
memset(book, 0, sizeof(book));
if (dfs(i))
ans++;
}
printf("Case %d: %d\n", cases++, ans);
}
return 0;
}
版权声明:转载请注明出处。
时间: 2024-10-01 02:30:49