Twenty Questions UVA
来源:互联网 发布:河南省农产品出口数据 编辑:程序博客网 时间:2024/05/05 07:04
按照紫书的思路递归求解即可,注意要找出最坏情况下的最好情况,具体实现见如下代码:
#include<iostream>#include<vector>#include<string>#include<set>#include<stack>#include<queue>#include<map>#include<algorithm>#include<cmath>#include<iomanip>#include<cstring>#include<sstream>#include<cstdio>#include<deque>using namespace std;int m, n;int dp[1<<12][1<<12],features[150];int getResult(int s1,int s2){if (dp[s1][s2] != -1) return dp[s1][s2];int amount = 0;for (int i = 0; i < n; i++){if ((s1&features[i])==s2) amount++;}if (amount <= 1){dp[s1][s2] = 0;return dp[s1][s2];}dp[s1][s2] = 1 << 30;for (int i = 0; i < m; i++){if (s1&(1 << i)) continue;dp[s1][s2] = min(dp[s1][s2], max(getResult(s1 | (1 << i), s2), getResult(s1 | (1 << i), s2 ^ (1 << i))) + 1);}return dp[s1][s2];}int main(){while (cin >> m >> n&&m&&n){string s;memset(features,0,sizeof(features));memset(dp,-1,sizeof(dp));for (int i = 0; i < n; i++){cin >> s;for (int j = 0; j < m; j++){if(s[j]!='0') features[i]|=(1<<j);}}cout << getResult(0, 0) << endl;}return 0;}
阅读全文
0 0
- UVA 1252 Twenty Questions
- UVa 1252 Twenty Questions
- uva 1252 Twenty Questions
- UVA 1252 Twenty Questions
- Twenty Questions UVA
- Twenty Questions UVA
- Twenty Questions UVA
- Twenty Questions UVA
- 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
- UVa-1252 Twenty Questions (位运算)
- uva 1252 - Twenty Questions(记忆化搜索)
- UVA 1252 Twenty Questions(状态压缩dp+记忆化)
- python 异常处理
- IDEA+Maven+SSH整合小结
- 震撼大气航拍尼亚加拉大瀑布视频素材4K航拍视频素材
- 【linux下 scrapy 安装】Python.h: No such file or directory
- 1065. A+B and C (64bit) (20)
- Twenty Questions UVA
- DroneKit教程(四):属性和参数的读取与设置
- 顺序表
- iOS 长按手势执行两次解决办法
- SpringMvc项目新建的详解配置
- Class 'org.springframework.orm.hibernate5.LocalSessionFactoryBean' not found
- 在pycharm中使用git版本管理以及同步github
- Android新特性介绍,ConstraintLayout完全解析
- 小工具-javascript实现进度条功能