博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
uva 11795 Mega Man's Mission(动态规划-状态压缩DP)
阅读量:4579 次
发布时间:2019-06-09

本文共 2735 字,大约阅读时间需要 9 分钟。

 

B

Mega Man’s Missions

Input

Standard Input

Output

Standard Output

 

Mega Man is off to save the world again. His objective is to kill the Robots created by Dr. Wily whose motive is to conquer the world. In each mission, he will try to destroy a particular Robot. Initially, Mega Man is equipped with a weapon, called the “Mega Buster” which can be used to destroy the Robots.  Unfortunately, it may happen that his weapon is not capable of taking down every Robot. However, to his fortune, he is capable of using the weapons from Robots which he has completely destroyed and these weapons maybe able to take down Robots which he otherwise cannot with his own weapon. Note that, each of these enemy Robots carry exactly one weapon themselves for fighting Mega Man.  He is able to take down the Robots in any order as long as he has at least one weapon capable of destroying the Robot at a particular mission. In this problem, given the information about the Robots and their weapons, you will have to determine the number of ways Mega Man can complete his objective of destroying all the Robots.

 

Input

Input starts with an integer T(T≤50), the number of test cases.

Each test case starts with an integer N(1≤N≤16). Here N denotes the number of Robots to be destroyed (each Robot is numbered from 1 to N). This line is followed by N+1 lines, each containing N characters. Each character will either be ‘1’ or ‘0’. These lines represent a (N+1)*N matrix. The rows are numbered from 0 to N while the columns are numbered from 1 to N. Row 0 represents the information about the “Mega Buster”. The jth character of Row 0 will be ‘1’ if the “Mega Buster” can destroy the jthRobot. For the remaining N rows, the jth character of ith row will be ‘1’ if the weapon of ith Robot can destroy the jth Robot. Note that, a Robot’s weapon could be used to destroy the Robot itself, but this will have no impact as the Robot must be destroyed anyway for its weapon to be acquired.

Output

For each case of input, there will be one line of output. It will first contain the case number followed by the number of ways Mega Man can complete his objective. Look at the sample output for exact format.

 

Sample Input

Sample Output

3

1

1

1

2

11

01

10

3

110

011

100

000

 

Case 1: 1

Case 2: 2

Case 3: 3

 

 

题目大意:

T组测试数据, 每组测试数据1个n,表示要杀n个人,接下来1行告诉你刚开始拥有杀哪些人的武器,例如“110”表示有杀第1,2个人的武器,接下来n行,分别表示杀完第i个人可以得到的杀其它人的武器。

解题思路:

状态DP,转移方程就是dp[x]=sum(dp[y]),其中y满足两个条件,(1)y是x的子状态,也就是y再杀一个人例如就到x。(2)y拥有杀k的武器。

解题思路:

#include 
#include
#include
using namespace std;typedef long long ll;const int maxn=(1<<20);ll dp[maxn];int n,wuqi[maxn];void input(){ scanf("%d",&n); for(int i=0;i<=(1<

转载于:https://www.cnblogs.com/toyking/p/3893178.html

你可能感兴趣的文章
iOS启动图 LaunchImage LaunchScreen.xib
查看>>
[转]利用/*+Ordered*/提高查询性能
查看>>
JdbcTemplate 操作Oracle Blob
查看>>
循序渐进地进行代码重构
查看>>
centos7 yum安装配置redis 并设置密码
查看>>
鸟哥私房菜第六章 用户与用户组
查看>>
LRU Cache数据结构简介
查看>>
17.2.2.1 The Slave Relay Log Slave中继日志
查看>>
3.1.2 MVC模式和URL访问
查看>>
node.js
查看>>
gcc编译
查看>>
如何配置Java EE Eclipse+Tomcat 开发环境
查看>>
Android水平(横向)翻页列表,类似水平GridVIew
查看>>
C#高级语法
查看>>
adbd cannot run as root in production builds
查看>>
数据结构实践——败者树归并模拟
查看>>
sum over 分析函数用法
查看>>
git的使用理解(分支合并的使用理解,多人编程的解决方案)
查看>>
Linux之线程相关命令及常用命令
查看>>
JS进阶
查看>>