题目传送门

 /*
题意:洛克人有武器可以消灭机器人,还可以从被摧毁的机器人手里得到武器,问消灭全部机器人的顺序总数
状态压缩DP:看到数据只有16,就应该想到状压(并没有)。因为是照解题报告写的,代码里加点注释,省的以后忘记了
*/
/************************************************
* Author :Running_Time
* Created Time :2015-8-8 10:41:28
* File Name :UVA_11759.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = ;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + ;
ll dp[(<<)+];
int w[MAXN];
int s[(<<)+];
char mega[MAXN];
char robot[MAXN];
int n; int main(void) { //UVA 11795 Mega Man's Mission
int T, cas = ; scanf ("%d", &T);
while (T--) {
scanf ("%d", &n);
scanf ("%s", mega); memset (w, , sizeof (w));
for (int i=; i<n; ++i) {
scanf ("%s", robot);
for (int j=; j<n; ++j) {
if (robot[j] == '') {
w[i] |= ( << j); //求出每个机器人拥有的武器,用二进制累加
}
}
} memset (s, , sizeof (s));
for (int i=; i<n; ++i) {
if (mega[i] == '') {
s[] |= ( << i); //求出洛克人手里的武器
}
}
for (int i=; i<(<<n); ++i) { //i表示机器人死亡的情况,例如00000表示一个都没消灭,11111表示全部消灭
s[i] = s[];
for (int j=; j<n; ++j) {
if (i & ( << j)) { //意思是当前第j个机器人被消灭
s[i] |= w[j]; //那么能得到它的武器
}
}
} memset (dp, , sizeof (dp)); dp[] = ; //一个都没被消灭的方案数为1
for (int i=; i<(<<n); ++i) {
if (!dp[i]) continue;
for (int j=; j<n; ++j) {
if ((s[i] & ( << j)) && (i & ( << j)) == ) { //意思是当前有武器能消灭第j个机器人并且要消灭它
dp[i|(<<j)] += dp[i]; //累加到消灭之后的状态里
}
}
}
printf ("Case %d: %lld\n", ++cas, dp[(<<n)-]); //111111全部都被消灭的方案数
} return ;
}

最新文章

  1. 关于这段时间学习 EntityFramework的 一点感悟
  2. 应用程序框架实战二十一:DDD分层架构之仓储(介绍篇)
  3. C++中关于文件的读写
  4. phpcms V9二次开发之联动菜单筛选 包括box字段的多选 单选 筛选教程
  5. 自定义滚动条样式(jQuery插件、Webkit、IE)
  6. 杂记 C中的volatile
  7. 我常用的Webstorm快捷键
  8. 用C#开发一个WinForm版的批量图片压缩工具
  9. 读书笔记-JavaScript中的全局对象
  10. AVPicture、AVFrame和AVPacket
  11. JQuery this和$(this)的区别及获取$(this)子元素对象的方法
  12. SQL SERVER 数据类型详解(SQL Server 2008)
  13. ProductHunt:创业公司产品猎场和秀场
  14. 基于visual Studio2013解决面试题之0305广度优先搜索二叉树
  15. bookStore项目总结
  16. Springboot+ActiveMQ(ActiveMQ消息持久化,保证JMS的可靠性,消费者幂等性)
  17. 学习笔记37—WIN7系统本地连接没有有效的IP地址 电脑本地连接无有效ip配置怎么办
  18. 将JDBC的resultSet映射到JavaBaen
  19. [svc]lnmp一键安装脚本(含有np与mysql分离)
  20. bzoj 1625: [Usaco2007 Dec]宝石手镯

热门文章

  1. Linux下汇编语言学习笔记17 ---
  2. 执行循环任务new Timer().schedule(new TimerTask(){},0,1000);
  3. java服务器图片压缩的几种方式及效率比较
  4. cogs——2419. [HZOI 2016]公路修建2
  5. P1765 手机_NOI导刊2010普及(10)
  6. operamasks—omMessageBox的使用
  7. mybatis resultmap标签type属性什么意思
  8. JAVA: 解决is expected to be of type but was actually of type com.sun.proxy.$Proxy的问题
  9. ppc_85xx-gcc -shared -fPIC liberr.c -o liberr.so
  10. Elasticsearch学习系列之mapping映射