Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=3605
EscapeTime limit:4000/2000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total Submission (s): 8001 Accepted Submission (s): 1758
Problem Description2012 If This is the end of the world? I don't know how. But now scientists has found that some stars, who can live, but some people does not fit to live some of the planet. Now scientists want your help, was to determine what's all of the people can live in these planets.
Inputmore set of test data, the beginning of each data is n (1 <= n <= 100000), M (1 <= m <=) n indicate th ere n people on the Earth, M representatives M planet, planet and people labels is from 0. Here's n lines, each line represents a suitable living conditions of people with each row have m digits, the ith digits is 1, said that's a person was fit to live in the Ith-planet, or was 0 for this person is not suitable for living in the ith planet .
The last line has m. digits, the ith digit AI indicates the ith planet can contain AI people most.
0 <= ai <= 100000
Outputdetermine whether all people can live up to these stars
If You can output YES, otherwise output NO.
Sample Input
1 1112 21 01 01 1
Sample Output
YESNO
Source
Field=problem&key=2010+acm-icpc+multi-university+training+contest%a3%a817%a3%a9%a1%aa%a1%aahost+by+zstu &source=1&searchmode=source ">2010 acm-icpc multi-university Training Contest (+)--host by Zstu
The main problem: N (n<100,000) individuals to go to M (m<10) planet. Each person can only go to some planets. A planet accommodates up to ki individuals. Output whether all people can choose their own planet.
problem-solving ideas: placed a very long topic, has been tle, today turned out to change or tle~~~~ bigger than the spring Festival, not to AC. because n is very large, M is very small. The array of tags is not too big, 15 is enough. Solving multiple matches is to record a multiple-match point (referred to as the Y-square point) that has matched the pi points.
Suppose Pi<ki so directly on, otherwise the words continue to search Yi has matched each point and Yi Dyeing, because Yi Search once need to dye. And the Y-side point is up to 10, so the depth of each finding of the augmented road is 10, so it is very fast. (use C + + to turn it)
See the code.
#include <iostream> #include <cstdio> #include <cstring>using namespace Std;int n,m;int w[15],cnt[15] ; int Map[100010][12],mat[12][100010];bool Vis[15];bool Find (int x) {for (int i=0;i<m;i++) if (!vis[i]&&map[x ][i]) {vis[i]=1;if (Cnt[i]<w[i]) {Mat[i][cnt[i]++]=x;return true;} for (int j=0;j<cnt[i];j++) if (Find (Mat[i][j])) {Mat[i][j]=x;return true;}} return false;} BOOL Ok () {memset (cnt,0,sizeof (CNT)); for (int i=0;i<n;i++) {memset (vis,0,sizeof (VIS)); Find (i)) return false;} return true;} int main () {while (~scanf ("%d%d", &n,&m)) {for (Int. i=0;i<n;i++) for (int j=0;j<m;j++) scanf ("%d", &map[ I][J]); for (int i=0;i<m;i++) scanf ("%d", &w[i]); if (ok () ==1) printf ("yes\n"); else printf ("no\n");} return 0;}
Hdu 3605 Escape binary matching (Hungarian algorithm)