HDU 6321 Dynamic Graph Matching (状压DP)

Problem C. Dynamic Graph Matching

Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)

Total Submission(s): 1796 Accepted Submission(s): 731

Problem Description

In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices.

You are given an undirected graph with n vertices, labeled by 1,2,...,n. Initially the graph has no edges.

There are 2 kinds of operations :

  • u v, add an edge (u,v) into the graph, multiple edges between same pair of vertices are allowed.
  • u v, remove an edge (u,v), it is guaranteed that there are at least one such edge in the graph.

    Your task is to compute the number of matchings with exactly k edges after each operation for k=1,2,3,...,n2. Note that multiple edges between same pair of vertices are considered different.

Input

The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.

In each test case, there are 2 integers n,m(2≤n≤10,nmod2=0,1≤m≤30000), denoting the number of vertices and operations.

For the next m lines, each line describes an operation, and it is guaranteed that 1≤u<v≤n.

Output

For each operation, print a single line containing n2 integers, denoting the answer for k=1,2,3,...,n2. Since the answer may be very large, please print the answer modulo 109+7.

Sample Input

1

4 8

+ 1 2

+ 3 4

+ 1 3

+ 2 4

- 1 2

- 3 4

+ 1 2

+ 3 4

Sample Output

1 0

2 1

3 1

4 2

3 1

2 1

3 1

4 2

题目解析

题意:给一个图有N个点和若干个询问,每个询问增或者删一条边,每个询问输出选择1~N/2条不相交的边的方案数。

题解:状压DP

代码

#include<bits/stdc++.h>
#define CLR(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
ll dp[1<<10];
ll ans[6]; int main()
{
// freopen("c.in","r",stdin);
// freopen("ans.txt","w",stdout);
int t,n,m,x,y,cnt;
ll tmp;
char s[2];
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
CLR(ans,0);
CLR(dp,0);
dp[0] = 1;
for(int i = 1; i <= m; i++){
scanf("%s %d %d",s,&x,&y);
if( s[0] == '+'){
for(int i = 0;i < (1<<n); i++){
if((i&(1<<(x-1))) && (i&(1<<(y-1)))){
tmp = dp[i];
dp[i] = (dp[i] + dp[(i^(1<<(x-1))^(1<<(y-1)))])%mod;
cnt = 0;
for(int j = 0; j < n; j++){
if(i&(1<<j)) cnt++;
}
ans[cnt/2] = (ans[cnt/2] + (dp[i]-tmp)%mod + mod )%mod; }
}
}
if( s[0] == '-'){
for(int i = 0;i < (1<<n); i++){
if((i&(1<<(x-1))) && (i&(1<<(y-1)))){
tmp = dp[i];
dp[i] = (dp[i]-dp[(i^(1<<(x-1))^(1<<(y-1)))] + mod)%mod; cnt = 0;
for(int j = 0; j < n; j++){
if(i&(1<<j)) cnt++;
}
ans[cnt/2] = (ans[cnt/2]+(dp[i]-tmp)%mod + mod)%mod;
}
}
} printf("%d",ans[1]%mod);
for(int i = 2; i <= n/2; i++){
printf(" %d",ans[i]%mod);
}
printf("\n");
}
}
return 0;
} /*
1
4 8
+ 1 2
+ 3 4
+ 1 3
+ 2 4
- 1 2
- 3 4
+ 1 2
+ 3 4
*/

HDU 6321 Dynamic Graph Matching的更多相关文章

  1. hdu多校第3场C. Dynamic Graph Matching

    Problem C. Dynamic Graph Matching Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Tot ...

  2. HDU6321 Dynamic Graph Matching【状压DP 子集枚举】

    HDU6321 Dynamic Graph Matching 题意: 给出\(N\)个点,一开始没有边,然后有\(M\)次操作,每次操作加一条无向边或者删一条已经存在的边,问每次操作后图中恰好匹配\( ...

  3. HDU - 6321 Problem C. Dynamic Graph Matching (状压dp)

    题意:给定一个N个点的零图,M次操作,添加或删除一条边,每一次操作以后,打印用1,2,...N/2条边构成的匹配数. 分析:因为N的范围很小,所以可以把点的枚举状态用二进制表示集合.用一维数组dp[S ...

  4. 【hdu 6321】Dynamic Graph Matching

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] DP 设f[i][j]表示前i个操作,已经匹配了的点的状态集合为j的方案数 对于+操作 有两种情况. 1.这条边作为匹配的边 2.这 ...

  5. HDU6321 Dynamic Graph Matching (杭电多校3C)

    给出一些点集,然后对于每一次要求给出的这些点集里的1,2,3,4,5,6....n/2的匹配数, dp[i][j] 表示到第i次操作里点集为j的匹配数,然后我每次加入一条边u-v,我的状态就是 dp[ ...

  6. [HDU6321]Dynamic Graph Matching(DP)

    题意:给定一个n个点的无向图,开始没有边,然后m个操作,每次加边或者删边,每次操作后输出正好k个边的匹配数k=1,2,3,...n/2,n<=10,m<=30000 可以发现,n<= ...

  7. 论文阅读笔记(十七)【ICCV2017】:Dynamic Label Graph Matching for Unsupervised Video Re-Identification

    Introduction 文章主要提出了 Dynamic Graph Matching(DGM)方法,以非监督的方式对多个相机的行人视频中识别出正确匹配.错误匹配的结果.本文主要思想如下图: 具体而言 ...

  8. Deep Learning of Graph Matching 阅读笔记

    Deep Learning of Graph Matching 阅读笔记 CVPR2018的一篇文章,主要提出了一种利用深度神经网络实现端到端图匹配(Graph Matching)的方法. 该篇文章理 ...

  9. Dynamic Route Matching Vue路由(1)

    Dynamic Route Matching 动态的 路由 匹配 Very often we will need to map routes with the given pattern to the ...

随机推荐

  1. pycharm实用快捷键集锦

    以下是本人需要记录的快捷键,并不针对大众,所以是断断续续补充的,大家看看图个乐呵就成! 生成代码块(Surround with):Ctrl + Alt + t . 历史浏览页面跳转:很多时候,我们需要 ...

  2. Codeforces Round #501 (Div. 3) D. Walking Between Houses

    题目链接 题意:给你三个数n,k,sn,k,sn,k,s,让你构造一个长度为k的数列,使得相邻两项差值的绝对值之和为sss, ∑i=1n∣a[i]−a[i−1]∣,a[0]=1\sum_{i=1}^n ...

  3. 树链剖分详解(洛谷模板 P3384)

    洛谷·[模板]树链剖分 写在前面 首先,在学树链剖分之前最好先把 LCA.树形DP.DFS序 这三个知识点学了 emm还有必备的 链式前向星.线段树 也要先学了. 如果这三个知识点没掌握好的话,树链剖 ...

  4. Angular7_人员登记系统

    1.ts public peopleInfo: any = { username: 'kxy', sex: '男', cityList: ['汕头', '广州', '茂名'], city: '汕头', ...

  5. python 模块 wmi 远程连接 windows 获取配置信息

    测试工具应用: https://ask.csdn.net/questions/247013 wmi连接不上报错问题集 https://blog.csdn.net/xcntime/article/det ...

  6. 【原创】大数据基础之Ambari(2)通过Ambari部署ElasticSearch(ELK)

    ambari2.7.3(hdp3.1) 安装 elasticsearch6.3.2 ambari的hdp中原生不支持elasticsearch安装,下面介绍如何通过mpack方式使ambari支持el ...

  7. iOS开发多线程之NSThread

    一.NSThread的属性与方法 1.NSThread 类方法 类方法,顾名思义通过类名直接调用的方法 1. + (void)detachNewThreadWithBlock:(void (^)(vo ...

  8. RedHat 6配置yum源为网易镜像(转)

    概述 由于版权的问题,RedHat6不能直接使用yum一些指令,需要配置yum源为网易镜像,但是网上谈到很多:整理一下,将有用的信息整理如下,以便于能够为其他的配置服务配置使用:需要卸载掉原理系统自带 ...

  9. tensorflow结果可视化-【老鱼学tensorflow】

    这次我们把上次的结果进行可视化显示,我们会把神经网络的优化过程以图像的方式展示出来,方便我们了解神经网络是如何进行优化的. 首先,我们把测试数据显示出来: # 显示测试数据 fig = plt.fig ...

  10. SA:利用SA算法解决TSP(数据是14个虚拟城市的横纵坐标)问题——Jason niu

    %SA:利用SA算法解决TSP(数据是14个虚拟城市的横纵坐标)问题——Jason niu X = [16.4700 96.1000 16.4700 94.4400 20.0900 92.5400 2 ...