uva 1252——Twenty Questions
来源:互联网 发布:lua for windows 5.1 编辑:程序博客网 时间:2024/05/09 06:19
题意:给定n个物品,每个物品用01串表示,表示具备与否某个特征,然后每次可以询问一个特征,问最少询问几次能够确定一个物品。
思路:状压Dp,将这些数的特征压缩成一个数,把询问过的和没询问的都用一集合表示,然后枚举没有询问的记忆化搜索。
code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <sstream>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=9999999;const int inf=-INF;const int N=135;const int M=2048+472;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define ft(i,s,n) for (int i=s;i<=n;i++)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);int n,m,d[M][M],cnt[M][M];string v[N];int dp(int s,int a){ int& ans=d[s][a]; if (cnt[s][a]<=1) return ans=0; if (ans>=0) return ans; ans=m; ft(i,0,m-1) if (!(s&(1<<i))) ans=min(ans,max(dp(s|(1<<i),a),dp(s|(1<<i),a|(1<<i)))+1); return ans;}int main(){ while (~scanf("%d %d",&m,&n),m+n) { cls(d,-1);cls(cnt,0); ft(i,0,n-1) cin>>v[i]; ft(i,0,n-1) { int t=0; ft(j,0,m-1) if (v[i][j]!='0') t|=(1<<j); ft(j,0,(1<<m)-1) cnt[j][t&j]++; } printf("%d\n",dp(0,0)); }}
0 0
- uva 1252——Twenty Questions
- UVA 1252 Twenty Questions
- UVa 1252 Twenty Questions
- uva 1252 Twenty Questions
- UVA 1252 Twenty Questions
- Twenty Questions - UVa 1252 dp
- UVA 1252(p287)----Twenty Questions
- UVA 1252 Twenty Questions | dp_状态压缩
- uva 1252 Twenty Questions 状压dp
- UVA 1252 Twenty Questions 状压DP
- UVa #1252 Twenty Questions (例题9-16)
- UVa-1252 Twenty Questions (位运算)
- Twenty Questions UVA
- Twenty Questions UVA
- Twenty Questions UVA
- Twenty Questions UVA
- 1252 - Twenty Questions
- uva 1252 - Twenty Questions(记忆化搜索)
- codeforces 488 E. Prefix Product Sequence
- ListView之ArrayAdapter详解
- DivX/XviD -opencv 视频文件读取显示问题解决
- LibSVM数据分类预测
- 关于eclipse android ctrl + 左键(鼠标左键)直接打开xml文件
- uva 1252——Twenty Questions
- 12、Integer to Roman
- 【Leetcode】First Missing Positive
- PHP哈希表结构的深入剖析
- Android自定义ProgressDialog
- Struts2 使用Validation框架验证数据
- nyoj 545 Metric Matrice【矩阵】水题
- [LeetCode]014-Longest Common Prefix
- FPGA学习之按键控制led