十五 Twenty Questions

Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

Appoint description: 
System Crawler  (2015-08-25)

Description

 

Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with ``yes" or ``no". Using those features, we can identify any object from the rest of the objects in the world. In other words, each object can be represented as a fixed-length sequence of booleans. Any object is different from other objects by at least one feature.

You would like to identify an object from others. For this purpose, you can ask a series of questions to someone who knows what the object is. Every question you can ask is about one of the features. He/she immediately answers each question with ``yes" or ``no" correctly. You can choose the next question after you get the answer to the previous question.

You kindly pay the answerer 100 yen as a tip for each question. Because you don't have surplus money, it is necessary to minimize the number of questions in the worst case. You don't know what is the correct answer, but fortunately know all the objects in the world. Therefore, you can plan an optimal strategy before you start questioning.

The problem you have to solve is: given a set of boolean-encoded objects, minimize the maximum number of questions by which every object in the set is identifiable.

Input

The input is a sequence of multiple datasets. Each dataset begins with a line which consists of two integers, m and n: the number of features, and the number of objects, respectively. You can assume 0 < m11 and 0 < n128. It is followed by n lines, each of which corresponds to an object. Each line includes a binary string of length m which represent the value (``yes" or ``no") of features. There are no two identical objects.

The end of the input is indicated by a line containing two zeros. There are at most 100 datasets.

Output

For each dataset, minimize the maximum number of questions by which every object is identifiable and output the result.

Sample Input

8 1
11010101
11 4
00111001100
01001101011
01010000011
01100110001
11 16
01000101111
01011000000
01011111001
01101101001
01110010111
01110100111
10000001010
10010001000
10010110100
10100010100
10101010110
10110100010
11001010011
11011001001
11111000111
11111011101
11 12
10000000000
01000000000
00100000000
00010000000
00001000000
00000100000
00000010000
00000001000
00000000100
00000000010
00000000001
00000000000
9 32
001000000
000100000
000010000
000001000
000000100
000000010
000000001
000000000
011000000
010100000
010010000
010001000
010000100
010000010
010000001
010000000
101000000
100100000
100010000
100001000
100000100
100000010
100000001
100000000
111000000
110100000
110010000
110001000
110000100
110000010
110000001
110000000
0 0

Sample Output

0
2
4
11
9
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int M=(<<)+;
const int inf=0x3f3f3f3f;
int p[],n,m;
int dp[M][M];
char a[]; int dfs(int s1,int s2)
{
int cnt=,i,j;
if(dp[s1][s2]<inf)
return dp[s1][s2];
for(i=;i<n;i++)
{
if((p[i] & s1)==s2)
{
cnt++;
}
} if(cnt<=)
{
dp[s1][s2]=;
return ;
} for(i=;i<m;i++)
{
if(s1 & (<<i))
continue;
int nex=s1 | (<<i);
dp[s1][s2]=min(dp[s1][s2],max(dfs(nex,s2),dfs(nex,s2^(<<i)))+);
}
return dp[s1][s2];
} int main()
{
int i,j,k;
while(scanf("%d %d",&m,&n)!=EOF)
{
if(n== && m==)
break;
memset(p,,sizeof(p));
memset(dp,inf,sizeof(dp)); for(i=;i<n;i++)
{
scanf("%s",a);
for(j=;j<m;j++)
{
if(a[j]=='')
p[i]=p[i] | (<<j);
}
} printf("%d\n",dfs(,));
}
return ;
}

UVA 1252 十五 Twenty Questions的更多相关文章

  1. 状压DP+记忆化搜索 UVA 1252 Twenty Questions

    题目传送门 /* 题意:给出一系列的01字符串,问最少要问几个问题(列)能把它们区分出来 状态DP+记忆化搜索:dp[s1][s2]表示问题集合为s1.答案对错集合为s2时,还要问几次才能区分出来 若 ...

  2. 我的MYSQL学习心得(十五) 日志

    我的MYSQL学习心得(十五) 日志 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据 ...

  3. Bootstrap <基础二十五>警告(Alerts)

    警告(Alerts)以及 Bootstrap 所提供的用于警告的 class.警告(Alerts)向用户提供了一种定义消息样式的方式.它们为典型的用户操作提供了上下文信息反馈. 您可以为警告框添加一个 ...

  4. Bootstrap<基础十五> 输入框组

    Bootstrap 支持的另一个特性,输入框组.输入框组扩展自 表单控件.使用输入框组,可以很容易地向基于文本的输入框添加作为前缀和后缀的文本或按钮. 通过向输入域添加前缀和后缀的内容,您可以向用户输 ...

  5. 解剖SQLSERVER 第十五篇 SQLSERVER存储过程的源文本存放在哪里?(译)

    解剖SQLSERVER 第十五篇  SQLSERVER存储过程的源文本存放在哪里?(译) http://improve.dk/where-does-sql-server-store-the-sourc ...

  6. Senparc.Weixin.MP SDK 微信公众平台开发教程(十五):消息加密

    前不久,微信的企业号使用了强制的消息加密方式,随后公众号也加入了可选的消息加密选项.目前企业号和公众号的加密方式是一致的(格式会有少许差别). 加密设置 进入公众号后台的“开发者中心”,我们可以看到U ...

  7. 十五个常用的jquery代码段【转】

    好的文章顶一个 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top 2 $('a.t ...

  8. 十五个常用的jquery代码段

    十五个常用的jquery代码段 回到顶部按钮 通过使用 jQuery 中的 animate 和 scrollTop 方法,你无需插件便可创建一个简单地回到顶部动画: 1 // Back to top ...

  9. 淘宝(阿里百川)手机客户端开发日记第十五篇 JSON解析(四)

    解析一个从淘宝传递的JSON (大家如有兴趣可以测试下):{ "tae_item_detail_get_response": { "data": { " ...

随机推荐

  1. qsort函数用法(转)

    qsort函数用法   qsort 功 能: 使用快速排序例程进行排序  用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(c ...

  2. 白盒测试的学习之路----(四)搭建测试框架TestNG测试

    TestNG是一个开源自动化测试框架; TestNG是类似于JUnit,但它不是一个JUnit扩展.它的灵感来源于JUnit.它的目的是优于JUnit的,尤其是当测试集成的类. TestNG消除了大部 ...

  3. asp.net项目发布网上-当前自定义错误设置禁止远程查看应用程序

    早上服务器的系统突然出错了,悲剧~ ==============异常信息:============================== 服务器上出现应用程序错误.此应用程序的当前自定义错误设置禁止远程 ...

  4. scala伴生对象

    package com.test.scala.test /** * 伴生对象指的是在类中建立一个object */ class AssociatedObject { private var count ...

  5. ubuntu下配置tomcat

    配置tomcat 1.解压 tar -zxvf apache-tomcat-7.0.53.tar.gz 2.修改/bin/catalina.sh cygwin=falsedarwin=falseos4 ...

  6. Java中IO流中所涉及到的各类方法介绍

    IO流之字节流 (1)IO用于在设备间进行数据传输的操作 (2)分类: A:流向 输入流 读取数据 输出流 写出数据 B:数据类型 字节流 字节输入流 字节输出流 字符流 字符输入流 字符输出流 注意 ...

  7. 使用BBCP来提升跨互联网的数据传输速度

    背景介绍: 目前项目在美国东西部以及欧洲都有服务器节点,跨互联网的数据传输速度很不稳定,之前我们主要是通过SCP以及Rsync等方式进行数据传输的. 无意间发现了BBCP这个软件之后,经过测试,效果非 ...

  8. 源码安装Apache,报错:Cannot use an external APR with the bundled APR-util和httpd: Could not reliably determine the server's fully qualified domain name, using

    一.解决APR和APR-util错误: 1.1.安装APR: [root@ganglia httpd-2.2.23]# cd srclib/apr [root@ganglia apr]# ./conf ...

  9. php curl语句的用法

    system32文件夹下,修改php.ini文件,找到;extension= php_curl.dll行,去掉前面的;号,保存,重启服务器.在站点目录下建立一个PHP文件,内容如下 $ch = cur ...

  10. 本人整理的一些PHP常用函数

    <?php //===============================时间日期=============================== //y返回年最后两位,Y年四位数,m月份数字 ...