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 题意:一个人到一些地方送披萨,要求找到一条路径能够遍历每一个城市后返回出发点,并且路径距离最短.最后输出最短距离即可.注意:每一 ...
随机推荐
- spring batch的使用和定时器Quart的使用
Spring Batch是一个基于Spring的企业级批处理框架,它通过配合定时器Quartz来轻易实现大批量的数据读取或插入,并且全程自动化,无需人员管理. 在使用spring batch之前,得对 ...
- Linux学习之十五-Linux文件特殊权限和附加权限
Linux文件特殊权限和附加权限 1.特殊权限suid 范围:只能针对二进制命令文件 作用:让普通用户拥有二进制命令文件所有者的权限 举例1:普通用户使用passwd命令修改密码 cat /etc/s ...
- xml 文件不给提示(以mybatis 的 mapper映射文件为例)
在xxx.xml 映射文件的头部可以看到 如下: (mybatis generate 自动生成) <!DOCTYPE mapper PUBLIC "-//mybatis.org//DT ...
- SVN切分支步骤
1.右键project选择Brankch/Tag 2.选择SVN路径并在改路径下填写project名称 3.选择最新版本号 4.填写必要的凝视备忘,方便日后查看 5.刷新父文件夹文件夹.下载被切出来的 ...
- UISegmentedControl的具体使用
当用户输入不不过布尔值时.可使用分段控件(UISegmentedControl).分段控件提供一栏button(有时称为button栏),但只能激活当中一个button. 分段控件会导致用户在屏幕上看 ...
- VELT-0.1.5开发:在VS2013下进行python开发
快乐虾 http://blog.csdn.net/lights_joy/(QQ群:Visual EmbedLinux Tools 375515651) 欢迎转载,但请保留作者信息 本文仅适用于vs20 ...
- Oracle 使用TRUNCATE TABLE删除所有行
若要删除表中的所有行,则 TRUNCATE TABLE 语句是一种快速.有效的方法.TRUNCATE TABLE 与不含 WHERE 子句的 DELETE 语句类似.但是,TRUNCATE TABLE ...
- wifi认证Portal开发系列(四):portal协议的java封装
一.报文封装类 AbstractPortalMsg.java Portal协议数据报文封装类 package org.yoki.edu.common.protocol.portal.msg; imp ...
- Delphi列表控件TListView定位到某一行。
ListView1.Item[100].Focused = true; //定位到索引为100的行ListView1.Item[100].Selected = true; ListView1.Item ...
- js中insertAdjacentHTML的玩法
原型:insertAdajcentHTML(swhere,stext) insertAdjacentHTML方法:在指定的地方插入html标签语句 参数:swhere: 指定插入html标签语句的地方 ...