UVA-1252 Twenty Questions

Source: Internet
Author: User

Pressure DP, which represents the characteristic that has been asked, a for W.

There is no need to guess when there is only one object that satisfies the condition. The number of objects that satisfy the condition can be preprocessed.

The request should be enumerated when the K is transferred, because the actual item to be guessed is indeterminate, either K is W, or K is not W,

To ensure that you can guess then you should take the worst case minimum, so there is a transfer equation: dp[s][a] = min (max (dp[s|1<<k][a],dp[s|1<<k][a|1<<k)).

The inquiry feature may be transferred to an illegal state where the number of items satisfying the condition is 0. According to the transfer equation should return 0.

#include <bits/stdc++.h>using namespacestd;Const intMAXM = One, MAXN = the;intcnt[1<<maxm][1&LT;&LT;MAXM], M, N, dp[1<<maxm][1<<Maxm];bitset<maxm>OBJ[MAXN];Const intINF =0x3fffffff;voidPredeal () { for(ints =0, M =1<<m; s < M; s++) {Fill (Cnt[s],cnt[s]+s+1,0); Fill (Dp[s],dp[s]+s+1, INF);  for(inti =0; I < n; i++) {Cnt[s][obj[i].to_ulong ()&s]++; }    }}intDfsintSinta) {    if(Cnt[s][a] <=1)return  0; int&ans =Dp[s][a]; if(Ans<inf)returnans;  for(intK =0; K < M; k++){        if(s&1&LT;&LT;K)Continue; intNS = s|1<<K; Ans= Min (Ans,max (DFS (ns,a), DFS (ns,a|1&LT;&LT;K)) +1); }    returnans;}intMain () {//freopen ("In.txt", "R", stdin);     while(SCANF ("%d%d\n",&m,&N), m) { for(inti =0; I < n; i++) {cin>>Obj[i];        } predeal (); printf ("%d\n", DFS (0,0)); }    return 0;}

UVA-1252 Twenty Questions

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.