uva11795
这题说的是一个人要消灭 所有的机器人,但是他有他可以消灭的机器人,他可以通过它消灭的机器人的武器去消灭其他的机器人, 给了一个可以消灭的关系的矩阵,计算消灭这些机器人的顺序的不同方案是多少种 , 刚开始以为是方案数 而不是 消灭的顺序wa
我们可以知道dp[S] 这个集合的状态可以从 他的子集来, 枚举他的子集,这样可以从不同的子集来,这样我们每个点子被算一次
首先 要处理每个子集所能 到达的点的情况列举出来 , 进行预处理,得到答案
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn=;
int mto[maxn];
ll dp[<<];
char s1[maxn];
int P[<<];
int main(){
int cas;
scanf("%d",&cas);
for(int cc=; cc<=cas; ++cc){
int n;
scanf("%d",&n);
for(int i=; i<=n ; ++i){
scanf("%s",s1);
mto[i]=;
for(int j=; j<n; ++j)
if(s1[j]=='')
mto[i]|=(<<j);
}
for(int S=;S<(<<n) ;++S){
P[S]=mto[];
for(int i=; i<n; ++i)
if(S&(<<i))
P[S]=P[S]|mto[i+];
}
memset(dp,,sizeof(dp));
dp[]=;
for(int S=; S<(<<n); ++S){
for(int i=; i<n; ++i)
if( ( S&(<<i) ) &&( P[S^(<<i)]&(<<i) ) ){
dp[S]+= dp[S^(<<i)];
}
}
printf("Case %d: %lld\n",cc,dp[(<<n)-]); } return ;
}
uva11795的更多相关文章
- UVA11795 Mega Man's Mission
状压dp #include<cstdio> #include<cstdlib> #include<algorithm> #include<cstring> ...
- 【状压DP】【UVA11795】 Mega Man's Mission
传送门 Description 你要杀n个怪,每杀掉一个怪那个怪会掉落一种武器,这种武器可以杀死特定的怪.游戏初始你有一把武器,能杀死一些怪物.每次只能杀一只,求有多少种杀怪方法. Input 多组数 ...
- [置顶] 刘汝佳《训练指南》动态规划::Beginner (25题)解题报告汇总
本文出自 http://blog.csdn.net/shuangde800 刘汝佳<算法竞赛入门经典-训练指南>的动态规划部分的习题Beginner 打开 这个专题一共有25题,刷完 ...
- dp暑假专题 训练记录
A 回文串的最小划分 题意:给出长度不超过1000的字符串,把它分割成若干个回文字串,求能分成的最少字串数. #include <iostream> #include <cstdio ...
随机推荐
- BigDecimal类(精度计算类)的加减乘除
BigDecimal类 对于不需要任何准确计算精度的数字可以直接使用float或double,但是如果需要精确计算的结果,则必须使用BigDecimal类,而且使用BigDecimal类也可以进行大数 ...
- com.alibaba.fastjson.JSONException: default constructor not found. class ……
1.json工具类 package com.hyzn.fw.util; import java.util.List; import java.util.Map; import com.alibaba. ...
- 百度地图地址查询API使用
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgsAAALxCAIAAABdNHLmAAAgAElEQVR4nOy9/VMbZ5rvnf/hbM7zy3 ...
- Jquery跨域Ajax取值
HTML: $.ajax({ type: "get", async: false, url: "http://www.xxxxxx.com/otherLogin/chec ...
- linux下php安装
nginx中配置php: http://www.111cn.net/sys/nginx/64044.htm
- linux清理n天前的文件命令
记得有一次面试时问题改问题.现特此记录 find ${DATADIR}/user*.log -type f -mtime +1 -exec rm {} \; DATADIR是自己定义变量 -mtime ...
- idea的svn插件中compare with the same repository version和compare with latest repository version的区别?
Idea的svn插件中compare with the same repository version和compare with latest repository version的区别? 1.com ...
- 线段树(成段更新,区间求和lazy操作 )
hdu1556 Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- windows dos 常用命令行
有关某个命令的详细信息,请键入 HELP 命令名 dir (directory) :列出当前目录下的文件以及文件夹 md (make directory): 创建目录 rd (remove direc ...
- linux: convmv =-======pkgs.org
convmv 不同系统文件名转化 windows: gbk linux: utf8 wget--url coding. vim ---encoding,termcode, fileencoding, ...