Compression dp+ Memory Search UVA 1252 twenty Questions

Source: Internet
Author: User

Topic Portal

1 /*2 Test Instructions: Give a series of 01 strings, ask at least a few questions (column) can distinguish them3 State dp+ Memory Search: DP[S1][S2] Indicates that the problem set is S1. The answer to the wrong set for S2, but also asked several times to distinguish4 if the difference with the answer (self-formulation) is less than or equal to 1 o'clock, the evidence has been able to distinguish, backtracking. If you want to add a question, ask again.5 */6 /************************************************7 * Author:running_time8 * Created time:2015-8-13 10:54:269 * File Name:UVA_1252.cppTen  ************************************************/ One  A#include <cstdio> -#include <algorithm> -#include <iostream> the#include <sstream> -#include <cstring> -#include <cmath> -#include <string> +#include <vector> -#include <queue> +#include <deque> A#include <stack> at#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> in using namespacestd; -  to #defineLson L, Mid, RT << 1 + #defineRson mid + 1, R, RT << 1 | 1 -typedefLong Longll; the Const intMAXN = -+Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD = 1e9 +7;Panax Notoginseng intdp[(1<< One)+Ten][(1<< One)+Ten]; - intP[MAXN]; the Charstr[ -]; + intm, N; A  the intDFS (intS1,intS2) { +     if(DP[S1][S2]! = INF)returnDP[S1][S2]; -     intCNT =0; $      for(intI=1; i<=n; ++i) { $         if((P[i] & S1) = = s2) cnt++; -     } -     if(CNT <=1)   { the         returnDP[S1][S2] =0; -     }Wuyi      for(intI=0; i<m; ++i) { the         if(S1 & (1<< i))Continue; -         intNEX = S1 | (1<<i); WuDP[S1][S2] = min (Dp[s1][s2], Max (DFS (NEX, S2), DFS (NEX, S2 ^ (1<< i)) +1); -     } About  $     returnDP[S1][S2]; - } -  - intMainvoid)  {//UVA 1252 Twenty Questions A      while(SCANF ("%d%d", &m, &n) = =2) { +         if(!m &&!n) Break; the          for(intI=1; i<=n; ++i) { -scanf ("%s", str); P[i] =0; $              for(intj=0; j<m; ++j) { the                 if(Str[j] = ='1')  { theP[i] |= (1<<j); the                 } the             } -         } inMemset (DP, INF,sizeof(DP)); theprintf ("%d\n", DFS (0,0)); the     } About  the     return 0; the}

Compression dp+ Memory Search 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.