[SRM] 600 # div2 B Enumeration

Source: Internet
Author: User

There is a set and a target State goal. The current state is x = 0. Now there are some numbers in the set, after an exclusive or operation such as X = x | A [I], x = goal can be achieved. Q: The minimum number of elements in the set is deleted, so that the initial x = 0 cannot reach the target State.

Idea: srm600 # div2 finished Question A for a while, mainly because he did not know how to calculate the number of shuttle directly, and suddenly found that the brute force enumeration was feasible.

Therefore, question B is also influenced by enumeration. At the beginning, I wanted to determine how many subsets to delete, but it was really hard to decide. Then I want to enumerate every bit of goal (Binary), which is obviously feasible! However, due to the lack of strict thinking, the answer is not correct for a while. Final logic: For each digit of the goal, there are two cases: 1. If it is 0, the numbers whose value is 1 in the set may not be deleted; 2, when the value is 1, the numbers with the value of 1 in the set may have to be deleted (the reason is that the number with the value of 1 is deleted, and he cannot reach the target State ). But this is not enough! We must first exclude the numbers that can be deleted, and then enumerate the second case, and then take the minimum value that needs to be deleted as one.

# Include <bits/stdc ++. h> using namespace STD; Class orsolitairediv2 {public: int getminimum (vector <int>, INT) ;}; int orsolitairediv2: getminimum (vector <int> num, int aim) {// to enumerate each bit of aim, you must first determine which ones can be deleted, and then determine the minimum number of int ans to delete = 33; bool f [33]; int CNT = 0; memset (F, false, sizeof (f); For (INT I = 0; I <33; I ++) if (! (Aim & (1 <I) {for (Int J = 0; j <num. size (); j ++) if (Num [J] & (1 <I) f [J] = true ;}for (INT I = 0; I <33; I ++) if (aim & (1 <I) {CNT = 0; For (Int J = 0; j <num. size (); j ++) if (Num [J] & (1 <I ))&&! F [J]) CNT ++; ans = min (ANS, CNT) ;}cnt = 0; For (INT I = 0; I <num. size (); I ++) if (F [I]) CNT ++; ans = min (INT) num. size ()-CNT, ANS); Return ans ;}

 

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.