Multiple matching of HDU 3605 Escape binary (Hungarian algorithm)

Source: Internet
Author: User

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

Source2010 acm-icpc multi-university Training Contest (+)--host by Zstu
Main topic:N (n<100,000) individual to go to M (m<10) planet, each person can only go to some planets, a planet to accommodate Ki individual, output whether everyone can choose their own planet. problem-solving ideas: placed a long time of the topic, has been tle, today turned out to change or tle~~~~ big New Year's, not to AC. since n is large, m is small, the array of marks is not too large, 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. If Pi<ki so directly on, otherwise the words continue to search Yi has matched each point and will dye Yi,because Yi searches once need to dye, and y Square point is up to 10, so each find the depth of the augmentation road is 10, so soon!!! (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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.