HDU3811 Permutation —— 状压DP
题目链接:https://vjudge.net/problem/HDU-3811
Permutation
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 496 Accepted Submission(s): 238
But Bob think that some permutations are more beautiful than others. Bob write some pairs of integers(Ai, Bi) to distinguish beautiful permutations from ordinary ones. A permutation is considered beautiful if and only if for some i the Ai-th element of it is Bi. We want to know how many permutations of set {1, 2, ...., N} are beautiful.
There are two integers N and M in the first line of each test case. M lines follow, the i-th line contains two integers Ai and Bi.
Technical Specification
1. 1 <= T <= 50
2. 1 <= N <= 17
3. 1 <= M <= N*N
4. 1 <= Ai, Bi <= N
3 2
1 1
2 1
3 2
1 1
2 2
4 3
1 1
1 2
1 3
Case 2: 3
Case 3: 18
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e5;
const int MAXN = (<<)+; bool g[][];
LL dp[MAXN][];
int cnt[MAXN]; void init()
{
for(int s = ; s<MAXN; s++)
{
cnt[s] = ;
for(int j = ; j<; j++)
if(s&(<<j)) cnt[s]++;
}
} int main()
{
init();
int T, n, m, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
memset(g, false, sizeof(g));
for(int i = ; i<=m; i++)
{
int u, v;
scanf("%d%d", &u, &v);
g[u][v] = true;
} memset(dp, , sizeof(dp));
dp[][] = ;
for(int s = ; s<(<<n); s++)
{
for(int i = ; i<; i++)
{
for(int j = ; j<n; j++)
if(!(s&(<<j)))
dp[s|(<<j)][i|g[cnt[s]+][j+]] += dp[s][i];
}
}
printf("Case %d: %lld\n", ++kase, dp[(<<n)-][]);
}
}
HDU3811 Permutation —— 状压DP的更多相关文章
- HDU 3811 Permutation 状压dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3811 Permutation Time Limit: 6000/3000 MS (Java/Othe ...
- HDU 4917 Permutation(拓扑排序 + 状压DP + 组合数)
题目链接 Permutation 题目大意:给出n,和m个关系,每个关系为ai必须排在bi的前面,求符合要求的n的全排列的个数. 数据规模为n <= 40,m <= 20. 直接状压DP空 ...
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds Me ...
- CodeForces 327E Axis Walking(状压DP+卡常技巧)
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub ...
- ZOJ - 3777(状压dp)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...
- zoj3777 Problem Arrangement(状压dp,思路赞)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...
- BZOJ 1087: [SCOI2005]互不侵犯King [状压DP]
1087: [SCOI2005]互不侵犯King Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 3336 Solved: 1936[Submit][ ...
- nefu1109 游戏争霸赛(状压dp)
题目链接:http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1109 //我们校赛的一个题,状压dp,还在的人用1表示,被淘汰 ...
- poj3311 TSP经典状压dp(Traveling Saleman Problem)
题目链接:http://poj.org/problem?id=3311 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
随机推荐
- 转: 为什么做java的web开发我们会使用struts2,springMVC和spring这样的框架?
from: https://github.com/RubyLouvre/agate/issues/8 今年我一直在思考web开发里的前后端分离的问题,到了现在也颇有点心得了,随着这个问题的深入,再加以 ...
- Centos7 安装 Maven 3.5.*
下载 Apache Maven 访问 Maven官方网站,打开后找到下载链接,如下: 解压 tar zxvf apache-maven-3.5.3-bin.tar.gz 添加环境变量 打开 /etc/ ...
- 转python版本的curl工具pycurl学习
一 pycurl介绍 pycurl模块为libcurl库提供了一个python接口.libcurl是一个开源免费且方便快捷的基于客户端的url传输库,支持FTP,HTTP,HTTPS,IMAP,IMA ...
- 网络虚拟化基础协议之Geneve
网络虚拟化最基础的技术莫过于分层(Overlay.Underlay),要实现分层有两种手段.一个是映射(Mapping),一个是封装(Encapsulation). 映射,主要思路是转发时替换报文语义 ...
- 蓝桥杯OJ PREV-19 九宫重排
题目描写叙述: 历届试题 九宫重排 时间限制:1.0s 内存限制:256.0MB 问题描写叙述 如以下第一个图的九宫格中,放着 1~8 的数字卡片.另一个格子空着.与空格子相 ...
- 使用Docker开发NodeJs APP
英文版原文地址 这是两篇连载文章的第一篇,讲解了如何使用 Docker 替代 Vagrant 开发基于 Express 框架的NodeJs App的部分细节.不过,这次要增加点难度:我们要使用 con ...
- 【转】基于eclipse进行ndk开发的环境配置
前述虽然我们在其他的博文中(如https://blog.csdn.net/ericbar/article/details/76602720),早就用到了ndk,但如果想在Android设备运行包含这些 ...
- html 锚点定位
在html中设置锚点定位我知道的有几种方法.在此和大家分享一下: 1.使用id定位: <a href="#1F" name="1F">锚点1< ...
- Android-自定义广播不能用的可能的原因(sendbroadcast 不起效果)
参考博客:https://blog.csdn.net/chuyouyinghe/article/details/79424373 照着书上的源码将程序原封不动敲了一遍,但发现这特么怎么也收不到发出的广 ...
- (转)JavaScript中==和===的区别
== 用于比较 判断 两者相等 ==在比较的时候可以转自动换数据类型 ===用于严格比较 判断两者严格相等 ===严格比较,不会进行自动转换,要求进行比较的操作数必须类型 ...