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<<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<<K)Continue; intNS = s|1<<K; Ans= Min (Ans,max (DFS (ns,a), DFS (ns,a|1<<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