UVA 11205 The Broken pedometer

Source: Internet
Author: User

Original question:
Too many pictures, omitted ...
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= 2146
Topic links

Give you a data
1
3
1
1 0 1

Guess what the answer is (haha)
The answer is answered ~

Effect:
Don't get it wrong, it's not about getting rid of a line. (according to the method of removing a line to solve the same TM and the results of the sample, rely on!)
Instead, it gives you a matrix of 0 and 1, which now allows you to pick out the fewest number of columns, making the new matrix of the composition distinguishable from each line.

#include <bits/stdc++.h> using namespace std;
FStream in,out;
Vector<int> mark[15];//All 1 of the number of I is crammed into the mark[i], the bool Hash[32768];//hash sentenced to the weight int case,n,p,t;

    int ptwo[16];//hit table 2 n power int res[101];//input data int totalone (int x)//Calculate a number of binary containing 1 of the number {int coun=0;
        while (x) {x=x& (x-1);
    coun++;
} return Coun;
    } int main () {Ios::sync_with_stdio (false);
    Ptwo[0]=1;
    for (int i=1;i<=15;i++) ptwo[i]=ptwo[i-1]*2;
    for (int i=0;i<=32767;++i) Mark[totalone (i)].push_back (i);//Play Table cin>>case;
        while (case--) {cin>>p>>n;
            for (int i=1;i<=n;i++) {int tmp=0;
                for (int j=0;j<p;j++) {cin>>t;
            TMP+=T*PTWO[J];
        } res[i]=tmp;
        } if (n==1)//Pay attention to n==1 situation:
            {cout<<0<<endl;
        Continue
        } int flag; for (int i=1;i&lT;=p;++i) {for (int j=0;j<mark[i].size (); j + +) {memset (hash,0,sizeof (Ha
                SH));
                flag=0;
                    for (int k=1;k<=n;k++) {int tmp=mark[i][j]&res[k];//takes advantage of a bitwise operation to take a number of bits in a row
                        if (hash[tmp])//To determine whether to repeat, if the repetition of the number of columns removed is unreasonable {flag=1;
                    Break
                } else hash[tmp]=true;
                    } if (!flag)//If the hash is not repeated, then the description can represent each line {cout<<i<<endl;
                Break
        }} if (!flag) break;
}} return 0;

 }

Answer:
This question just read the question when read wrong, thought is to remove a line after looking for the smallest of the picture tube can still express each line, the most egg pain is the sample incredibly all over the Orz.
Before getting started the problem of state compression dynamic planning was inspired. First, all binary is enumerated, a bit is 1 for the column, and the number of binary 1 is recorded, and then the subscript is saved in mark by the number of 1.
For example Mark[3] will have such a few binary number 111,10101 ....
Then enumerate each binary number to remove the corresponding column, and then use the hash table to determine whether or not to repeat.

The answer is 0, uh, a.

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.