UVa 11205 Damaged Step count

Source: Internet
Author: User

Test instructions: There is a set of encodings that differentiate these encodings with the least number of bits.

Idea: the equivalent of enumerating all the subsets of a collection, and then selecting the smallest set of potential that meets the requirements.

There are three methods for subset generation, but the generation of each subset has no obvious regularity, at least not from the order of 1 elements, 2 elements to n elements, so it is necessary to enumerate all the subsets. The increment constructor is used here to enumerate the subsets.

Code:

#include <stdio.h>void print_subset (int p,int n,int *a, int cur); bool Have_same (int cur,int n); int codi[101][16];  int A[15+5];int Min;int Main () {//freopen ("11205.in", "R", stdin);      Freopen ("11205.out", "w", stdout);  int t;  scanf ("%d", &t);    while (t-->0) {min=20;    int p,n;    scanf ("%d%d", &p,&n);           for (int i=0;i<n;++i) for (int j=0;j<p;++j) {scanf ("%d", &codi[i][j]);    } print_subset (p,n,a,0);  printf ("%d\n", min);  } return 0;    }void print_subset (int p,int n,int *a, int cur) {if (cur && have_same (cur,n) ==false) min=cur<min?cur:min; int s=cur?  a[cur-1]+1:0;    for (int i=s;i<p;++i) {a[cur]=i;        Print_subset (p,n,a,cur+1); }}bool have_same (int cur,int n) {for (int. i=0;i<n;++i) {for (int j=i+1;j<n;++j) {bool flag=true;//labeled COD      I line I of array I and line J is the same as for (int m=0;m<cur;++m) {if (Codi[i][a[m]]!=codi[j][a[m]]) {flag=false;    } if (flag) return true; }       } return false; }


UVa 11205 Damaged Step count

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.