The broken pedometer ultraviolet A 11205

Source: Internet
Author: User

Let's talk about:

At the beginning of this question, I thought there was an error. I thought that as long as I had to judge each bit, that is, if the bit of each number is not considered, if two numbers are identical, this bit must exist. Otherwise, it is dispensable. However, this is actually a problem, because it means that the judgment of a person is based on other places by default. In fact, it is reasonable to judge the bit to be judged after all invalid bits are removed, but this is obviously not satisfactory. Therefore, I also read some other people's Problem Solving Report on the Internet. The simplest thing is to use the bitvector method. That is, to determine whether each bit of P is effectively arranged and combined, list all the situations, and solve the problem by brute force.


Source code:

# Include <stdio. h> # include <string. h> # define maxp 15 + 5 # define maxn 100 + 5int s [maxn] [maxp]; char CPY [maxn] [maxp]; char valid [maxp]; int N, p, ans; void solve (INT cur) {int I, j, count; If (cur = P) {COUNT = 0; // record the number of valid bits for (I = 0; I <p; I ++) if (valid [I]) {// fill in count ++; For (j = 0; j <n; j ++) based on the obtained data) CPY [J] [I] = '0' + s [J] [I];} else for (j = 0; j <n; j ++) // The invalid bit is directly set to 0 CPY [J] [I] = '0'; for (I = 0; I <n; I ++) CPY [I] [p] = '\ 0'; // do not forget to put the end ID of the string for (I = 0; I <n; I ++) for (j = I + 1; j <n; j ++) if (strcmp (CPY [I], CPY [J]) = 0) // If a duplicate is found, this sorting method does not support return; If (count <ans) ans = count; return;} valid [cur] = 0; // bit vector method, list all cases solve (cur + 1); valid [cur] = 1; solve (cur + 1); return;} int main () {int I, J, K, t; // freopen ("data", "r", stdin); scanf ("% d", & T); While (t --) {scanf ("% d", & P, & N); for (I = 0; I <n; I ++) for (j = 0; j <p; j ++) scanf ("% d", & S [I] [J]); ans = P; solve (0 ); printf ("% d \ n", ANS);} return 0 ;}

The broken pedometer ultraviolet A 11205

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.