"Binary Map Matching primer 1" n-special Fish hdu3395 "km algorithm" "Spring Breeze ten miles, are inferior to tle~~~"

Source: Internet
Author: User
Tags define local

There is a kind of special fish in the East Lake where was closed to campus of Wuhan University. It's hard to say which gender of those fish is, because every fish believes itself as a male, and it may attack one's so Me other fish are believed to be female by it.
A Fish would spawn after it had been attacked. Each fish can attack one other fish and can is only attacked once. No matter a fish is attacked or not, it can still try to attack another fish which are believed to being female by it.
There is a value we assigned to each fish and the spawns, and the fish spawned also has a value which can be calculated B Y XOR operator through the value of its parents.
We want to know the maximum possibility of the sum of the spawns.

Inputthe input consists of multiply test cases. The first line of all test case contains a integer n (0 < n <=), which is the number of the fish. The next line consists of n integers, indicating the value (0 < value <=) of each fish. The next n lines, each line contains n integers, represent a in the matrix. The i-th fish believes the j-th fish is female if and only if the value in row I and column J if 1.
The last test case was followed by a zero, which means the end of the input. Outputoutput the value for each test in a single line. Sample Input

31 2 30111011100

Sample Outpu6




First reflection!! Today, in addition to the title of the question is 1a, the rest of the tle,tle,tle,tle ... Oh, another 1wrong, really test my patience, and even more I put the end of the wrong condition, variable name mixed, define the global and define local variables.
This time again the problem of initialization, say, why the diagram initialized to-inf to timeout, initialized to 0 a.
Test instructions: give you the value of n fish, nth row and nth column 1, then the two are connected, the value of the two is the value of the difference or operation, ask the maximum matching value.
Idea: This diagram is relatively simple oh ~ as long as a different or operation is good, I feel this problem should be placed in the back of the J is appropriate AH.
#include <stdio.h>#include<string.h>#defineINF 0x3f3f3f3f#defineN 110intN;intV[n],w[n][n],lx[n],ly[n];intVisx[n],visy[n];intLinker[n];CharS[n][n];intD,ans;voidGetmap () {inti,j;  for(i =1; I <= N; i + +)         for(j =1; J <= N; J + +)            if(s[i][j]=='1') W[i][j]= v[i]^V[j]; return;}intDfsintx) {    inty,tmp; VISX[X]=1;  for(y =1; Y <= N; Y + +)    {        if(!Visy[y]) {tmp= Lx[x] + ly[y]-W[x][y]; if(!tmp) {Visy[y]=1; if(linker[y]==-1||DFS (Linker[y])) {Linker[y]=x; return 1; }            }            Else if(D >tmp) d=tmp; }    }    return 0;}intKMP () {intsum,x,i,j; MEMSET (linker,-1,sizeof(linker)); memset (ly,0,sizeof(ly));  for(i =1; I <= N; i + +)         for(j =1, Lx[i]=-inf; J <= N; J + +)            if(Lx[i] <W[i][j]) lx[i]=W[i][j];  for(x =1; x <= N; X + +)    {         while(1) {memset (VISX,0,sizeof(VISX)); memset (Visy,0,sizeof(Visy)); D=INF; if(Dfs (x)) Break;  for(i =1; I <= N; i + +)                if(Visx[i]) lx[i]-=D;  for(i =1; I <= N; i + +)                if(Visy[i]) ly[i]+=D; }} sum=0;  for(i =1; I <= N; i + +)        if(linker[i]!=-1) Sum+=W[linker[i]][i]; returnsum;}intMain () {inti,j;  while(SCANF ("%d", &n), n!=0) {memset (W,0,sizeof(w));  for(i =1; I <= N; i + +) scanf ("%d",&V[i]);        GetChar ();  for(i =1; I <= N; i + +) scanf ("%s", s[i]+1);        Getmap (); Ans=KMP (); printf ("%d\n", ans); }    return 0;}

"Binary Map Matching primer 1" n-special Fish hdu3395 "km algorithm" "Spring Breeze ten miles, are inferior to tle~~~"

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.