Problem C. Dynamic Graph Matching

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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 ,,...,n. Initially the graph has no edges.
There are 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=,,,...,n2. Note that multiple edges between same pair of vertices are considered different. Input
The first line of the input contains an integer T(≤T≤), denoting the number of test cases.
In each test case, there are integers n,m(≤n≤,nmod2=,≤m≤), denoting the number of vertices and operations.
For the next m lines, each line describes an operation, and it is guaranteed that ≤u<v≤n. Output
For each operation, print a single line containing n2 integers, denoting the answer for k=,,,...,n2. Since the answer may be very large, please print the answer modulo +. Sample Input +
+
+
+
-
-
+
+ Sample Output Source
Multi-University Training Contest Recommend
chendu Statistic | Submit | Discuss | Note

装压dp

+:操作很简单就是:dp[i]+=dp[i-(1<<u)-(1<<v)];

-:操作就想象成反的: dp[i]-=dp[i-(1<<u)-(1<<v)];拿总的减去用到用到u,v

类似于背包某个物品不能放;

#include <cstdio>
#include <cstring>
#include <iostream>
//#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
//#define mod 998244353
const int mod=1e9+; ll dp[<<];//dp[i]:i集合内点完全匹配的方案数
int bit[<<];//i的二进制的1个数;
ll ans[];
int lowbit(int x) {return x&-x;}
int calc(int x)
{
int res=;
while(x){res++;x=x-lowbit(x);}
return res;
}
int main()
{
for(int i=;i<(<<);i++)
bit[i]=calc(i);
int T,n,m,u,v;
char op[];
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(dp,,sizeof dp);
memset(ans,,sizeof ans);
dp[]=;
while(m--)
{
scanf("%s%d%d",op,&u,&v);
u--;v--;
if(op[]=='+')
{
for(int i=(<<n)-;i>;i--)
if(((<<u)&i)&&((<<v)&i))
{
dp[i]+=dp[i-(<<u)-(<<v)];
ans[bit[i]]+=dp[i-(<<u)-(<<v)]; //对于i集合所有点的匹配,会对ans造成的影响
dp[i]=dp[i]%mod;
ans[bit[i]]=ans[bit[i]]%mod;
}
} else
{
for(int i=;i<<<n;i++)
if(((<<u)&i)&&((<<v)&i))
{
dp[i]-=dp[i-(<<u)-(<<v)];
ans[bit[i]]-=dp[i-(<<u)-(<<v)];
dp[i]=(dp[i]+mod)%mod;
ans[bit[i]]=(ans[bit[i]]+mod)%mod;
}
}
for(int i=;i<=n;i=i+)
{
if(i!=)
cout<<" ";
printf("%lld",ans[i]); }
cout<<endl; } } return ;
}

hdu多校第3场C. Dynamic Graph Matching的更多相关文章

  1. 2018 HDU多校第三场赛后补题

    2018 HDU多校第三场赛后补题 从易到难来写吧,其中题意有些直接摘了Claris的,数据范围是就不标了. 如果需要可以去hdu题库里找.题号是6319 - 6331. L. Visual Cube ...

  2. 2018 HDU多校第四场赛后补题

    2018 HDU多校第四场赛后补题 自己学校出的毒瘤场..吃枣药丸 hdu中的题号是6332 - 6343. K. Expression in Memories 题意: 判断一个简化版的算术表达式是否 ...

  3. hdu多校第三场

    Problem D. Euler Function 思路:打表找找规律. #include<bits/stdc++.h> #define LL long long #define fi f ...

  4. HDU 6321 Dynamic Graph Matching

    HDU 6321 Dynamic Graph Matching (状压DP) Problem C. Dynamic Graph Matching Time Limit: 8000/4000 MS (J ...

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

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

  6. HDU多校训练第一场 1012 Sequence

    题目链接:acm.hdu.edu.cn/showproblem.php?pid=6589 题意:给出一个长度为n的数组,有m次操作,操作有3种1,2,3,问操作m次后的数组,输出i*a[i]的异或和 ...

  7. hdu多校第五场1005 (hdu6628) permutation 1 排列/康托展开/暴力

    题意: 定义一个排列的差分为后一项减前一项之差构成的数列,求对于n个数的排列,差分的字典序第k小的那个,n<=20,k<=1e4. 题解: 暴力打表找一遍规律,会发现,对于n个数的排列,如 ...

  8. Harvest of Apples (HDU多校第四场 B) (HDU 6333 ) 莫队 + 组合数 + 逆元

    题意大致是有n个苹果,问你最多拿走m个苹果有多少种拿法.题目非常简单,就是求C(n,0)+...+C(n,m)的组合数的和,但是询问足足有1e5个,然后n,m都是1e5的范围,直接暴力的话肯定时间炸到 ...

  9. 2014 HDU多校弟九场I题 不会DP也能水出来的简单DP题

    听了ZWK大大的思路,就立马1A了 思路是这样的: 算最小GPA的时候,首先每个科目分配到69分(不足的话直接输出GPA 2),然后FOR循环下来使REMAIN POINT减少,每个科目的上限加到10 ...

随机推荐

  1. python基础之 列表,元组,字典

    other help(str.strip) #查看是否有返回值以及返回值类型[] :称为索引操作符 1.列表 列表相比字符串来说能存储大量数据的python的基本数据类型,并且也拥有字符串的一些方法( ...

  2. [转] Mac系统Robot Framework环境搭建

    一.由于Mac系统下自带python,所以不需要再进行安装了 二.关闭mac电脑的sip, 1.重启 Mac并长按 Cmd + R 2.打开终端,执行csrutil disable命令 3.重启电脑 ...

  3. Kaggle初学者五步入门指南,七大诀窍助你享受竞赛

    Kaggle 是一个流行的数据科学竞赛平台,已被谷歌收购,参阅<业界 | 谷歌云官方正式宣布收购数据科学社区 Kaggle>.作为一个竞赛平台,Kaggle 对于初学者来说可能有些难度.毕 ...

  4. JS基本事件(小记)

    一.    事件的概念种类及作用(一)    概念:通常鼠标或热键的动作我们称之为事件(event),热键引发的一连串程序的动作,称之为事件驱动(event Driver).而对事件进行处理的程序或函 ...

  5. 将指定世界中的指定位置的Block转化为箱子

    在bukkit中,block可以操作所有的三位像素方块,如果是向对block进一步操作,我们就需要得到BlockState, BlockState表示一个方块的状态,才能够对方块进行位置等状态的操作, ...

  6. smtplib.SMTPDataError: (554, b'DT:SPM 163……)

    1.报错535: 未将POP3/SMTP服务开启.通过在163邮箱内 设置 获取授权码  打开,通过授权码可以进行第三方登录.此处的Password填写授权码. 2.报错554: 第一种情况:缺失发件 ...

  7. Windows下静态库与动态库的创建与使用

    Windows下静态库与动态库的创建与使用 学习内容:本博客介绍了Windows下使用Visual C++ 6.0制作与使用静态库与动态库的方法. --------CONTENTS-------- 一 ...

  8. xml 和 json 序列化忽略字段

    xml 和 json 序列化忽略字段: @JsonIgnore @XmlTransient

  9. Visual Studio 2017 最新全量离线下载方法[有惊喜]

    从官网下载的是 VS在线安装程序,也只有这个可以下载,官网并不提供离线包下载,那么如何创建离线安装包呢? 使用cmd命令:vs_enterprise__914632938.1491737491.exe ...

  10. Beaglebone板子修改usb连接时的默认IP192.168.0.2

    首先除了有个USB线外,你还需要一个USB转串口的线(目的是防止修改错误,无法使用原来的usb的IP地址登陆,心大的可以跳过这步直接进入重点),串口线连接方法如下图: ​ 将USB以及串口和PC机相连 ...