标签:hdu 3335 divisibilit 二分图
Divisibility
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1714 Accepted Submission(s): 651
Problem Description
As we know,the fzu AekdyCoin is famous of math,especially in the field of number theory.So,many people call him "the descendant of Chen Jingrun",which brings him a good reputation.
AekdyCoin also plays an important role in the ACM_DIY group,many people always ask him questions about number theory.One day,all members urged him to conduct a lesson in the group.The rookie daizhenyang is extremely weak at math,so he is delighted.
However,when AekdyCoin tells us "As we know, some numbers have interesting property. For example, any even number has the property that could be divided by 2.",daizhenyang got confused,for he don‘t have the concept of divisibility.He asks other people for help,first,he
randomizely writes some positive integer numbers,then you have to pick some numbers from the group,the only constraint is that if you choose number a,you can‘t choose a number divides a or a number divided by a.(to illustrate the concept of divisibility),and
you have to choose as many numbers as you can.
Poor daizhenyang does well in neither math nor programming.The responsibility comes to you!
Input
An integer t,indicating the number of testcases,
For every case, first a number n indicating daizhenyang has writen n numbers(n<=1000),then n numbers,all in the range of (1...2^63-1).
Output
The most number you can choose.
Sample Input
Sample Output
2
Hint:
If we choose 2 and 3,one is not divisible by the other,which is the most number you can choose.
Author
DaiZhenyang@BUPT
Source
题意:给你n个数,选最多的数使得两两之间不能整除。
题解:最大独立集 = 点数 - 二分图最大匹配
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
#define N 30030
#define M 100100
#define ll long long
using namespace std;
const int MAXN = 1010;
int n;
int g[MAXN][MAXN];
int linker[MAXN];
bool used[MAXN];
bool dfs(int u) {
for(int v = 0; v < n; v++)
if(g[u][v] && !used[v]) {
used[v] = true;
if(linker[v] == -1 || dfs(linker[v])) {
linker[v] = u;
return true;
}
}
return false;
}
int hungary() {
int res = 0;
memset(linker,-1,sizeof(linker));
for(int u = 0; u < n; u++) {
memset(used,false,sizeof(used));
if(dfs(u))res++;
}
return res;
}
ll a[MAXN];
int main() {
//freopen("test.in","r",stdin);
int t;
cin>>t;
while(t--) {
scanf("%d",&n);
for(int i=0; i<n; i++)
scanf("%I64d",&a[i]);
memset(g,0,sizeof g);
sort(a,a+n);
int ans=0;
for(int i=0; i<n; i++) {
for(int j=i+1; j<n; j++) {
if(a[j]%a[i]==0) {
g[i][j]=1;
}
}
}
printf("%d\n",n-hungary());
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 3335 Divisibility(二分图)
标签:hdu 3335 divisibilit 二分图
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/47739343