Domino (Codevs 3052)

Source: Internet
Author: User

Title Description Description

A rectangle can be divided into m*n small squares, in which some small squares cannot be used. A domino occupies two small squares adjacent to each other. How many dominoes can be placed in the entire area without overlapping, and not occupy any small squares that are marked as unusable.

Enter a description Input Description

The first line has two positive integers m and n separated by a space.

The second line has a positive integer k, which indicates that a total of k small squares are not available. Input data guarantees k<=m*n.

The following k lines each row has two X and Y separated by a space, indicating that the nth square of the X row cannot be used.

Output Description Output Description

The maximum number of dominoes the output can put.

Sample Input Sample Input

3 3

2

1 1

2 2

Sample Output Sample Output

3

data range and tips Data Size & Hint

For 30% of data, m=1;

For 50% of data,m<=2;

For 70% of data,m<=3;

For 100% of data, m<=50,n<=50.

/*the problem of binary graph matching is to select as many relationships as possible from a lump of lattice relationships, so that each square is selected only once. By observing we can find that the horizontal axis plus ordinate is an even number of squares can only match the odd squares, so it becomes a two-point graph matching problem. */#include<cstdio>#include<iostream>#include<cstring>#defineN 51using namespacestd;intg[n][n],n,m,p,head[n*n],cnt;intused[n*n],belong[n*N];structnode{intV,pre;}; Node E[n*n*2];voidAddintXinty) {e[++cnt].v=y; E[cnt].pre=Head[x]; HEAD[X]=CNT;}BOOLFindinti) {     for(intj=head[i];j;j=e[j].pre) {        if(!USED[E[J].V]) {USED[E[J].V]=1; if(!belong[e[j].v]| |find (BELONG[E[J].V])) {BELONG[E[J].V]=i; return true; }        }    }    return false;}intMain () {Freopen ("jh.in","R", stdin); scanf ("%d%d%d",&n,&m,&p);  for(intI=1; i<=p;i++){        intX,Y;SCANF ("%d%d",&x,&y); G[x][y]=1; }     for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if((i+j&1)|| G[I][J])Continue; if(!g[i-1][j]&&i-1>=1) Add ((I-1) *m+j, (I-2) *m+j); if(!g[i+1][j]&&i+1<=n) Add ((I-1) *m+j,i*m+j); if(!g[i][j-1]&&j-1>=1) Add ((I-1) *m+j, (I-1) *m+j-1); if(!g[i][j+1]&&j+1&LT;=M) Add ((I-1) *m+j, (I-1) *m+j+1); }    }    inttot=0;  for(intI=1; i<=n;i++){         for(intj=1; j<=m;j++){            if((i+j&1)|| G[I][J])Continue; memset (Used,0,sizeof(used)); if(Find (I-1) (*M+J)) tot++; }} printf ("%d", tot); return 0;}

Domino (Codevs 3052)

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.