状压DP UVA 11795 Mega Man's Mission
/*
题意:洛克人有武器可以消灭机器人,还可以从被摧毁的机器人手里得到武器,问消灭全部机器人的顺序总数
状态压缩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 ;
}
状压DP UVA 11795 Mega Man's Mission的更多相关文章
- 状压DP UVA 10817 Headmaster's Headache
题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...
- UVa 11795 Mega Man's Mission (状压DP)
题意:你最初只有一个武器,你需要按照一定的顺序消灭n个机器人(n<=16).每消灭一个机器人将会得到他的武器. 每个武器只能杀死特定的机器人.问可以消灭所有机器人的顺序方案总数. 析:dp[s] ...
- UVA - 11795 Mega Man's Mission
Mega Man is off to save the world again. His objective is to kill the Robots created by Dr. Wily who ...
- UVA 1412 Fund Management (预处理+状压dp)
状压dp,每个状态可以表示为一个n元组,且上限为8,可以用一个九进制来表示状态.但是这样做用数组开不下,用map离散会T. 而实际上很多九进制数很多都是用不上的.因此类似uva 1601 Mornin ...
- UVa 11825 (状压DP) Hackers' Crackdown
这是我做状压DP的第一道题,状压里面都是用位运算来完成的,只要耐下心来弄明白每次位运算的含义,还是容易理解的. 题意: 有编号为0~n-1的n台服务器,每台都运行着n中服务,每台服务器还和若干台其他服 ...
- 【状压DP】【UVA11795】 Mega Man's Mission
传送门 Description 你要杀n个怪,每杀掉一个怪那个怪会掉落一种武器,这种武器可以杀死特定的怪.游戏初始你有一把武器,能杀死一些怪物.每次只能杀一只,求有多少种杀怪方法. Input 多组数 ...
- UVa 1204 Fun Game (状压DP)
题意:有一些小孩(至少两个)围成一圈,有 n 轮游戏,每一轮从某个小孩开始往左或者往右伟手帕,拿到手帕写上自己的性别(B,G),然后以后相同方向给下一个. 然后在某个小孩结束,给出 n 轮手帕上的序列 ...
- UVa 11825 Hackers' Crackdown (状压DP)
题意:给定 n 个计算机的一个关系图,你可以停止每台计算机的一项服务,并且和该计算机相邻的计算机也会终止,问你最多能终止多少服务. 析:这个题意思就是说把 n 台计算机尽可能多的分成一些组,使得每组的 ...
- UVA - 1252 Twenty Questions (状压dp)
状压dp,用s表示已经询问过的特征,a表示W具有的特征. 当满足条件的物体只有一个的时候就不用再猜测了.对于满足条件的物体个数可以预处理出来 转移的时候应该枚举询问的k,因为实际上要猜的物品是不确定的 ...
随机推荐
- Mayor's posters POJ - 2528
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign h ...
- [bzoj1014][JSOI2008]火星人prefix_非旋转Treap_hash_二分
火星人prefix bzoj-1014 JSOI-2004 题目大意:给定一个字符串,支持三种操作:1.查询:两个后缀之间的$LCP$:2.单点修改:3.插入一个字符. 注释:$1\le n\le 1 ...
- POJ—— 2117 Electricity
Electricity Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5620 Accepted: 1838 Descr ...
- http转https
1.先用jdk生成证书 先跳转到jdk的bin目录下:E:\Program Files\Java\jdk1.8.0_91\bin>keytool -genkey -alias tomcat -k ...
- Servlet实现国际化
以下内容引用自http://wiki.jikexueyuan.com/project/servlet/internationalization.html: 三个重要术语: 国际化(i18n):这意味着 ...
- 学习javascript 非常好的博客
这个大牛写的非常好!!推荐一下 http://www.cnblogs.com/xiaohuochai/tag/javascript%E6%80%BB%E7%BB%93/default.html?pag ...
- java STW stop the world 哈哈就是卡住了
java STW stop the world 哈哈就是卡住了 学习了:http://www.jb51.net/article/125400.htm
- [AngularJS] ocLazyLoad -- Lazy loaded module should contain all the dependencies code
Recentlly works with AngularJS + ocLazyLoad, our project have break down into multi small modules. F ...
- Ubuntu14.04 忘记rootpassword的解决方法
对于windows操作系统,假设忘记管理员password,事实上还是蛮好解决的. 最简单的一种方式就是使用PE--电脑店,老毛桃等等,都能够非常完美的解决问题. 假设是Linux操作系统的话.事实上 ...
- Python3标准库(二) re模块
正则表达式(Regular Expression)是字符串处理的常用工具,通常被用来检索.替换那些符合某个模式(Pattern)的文本.很多程序设计语言都支持正则表达式,像Perl.Java.C/C+ ...