1. Problem C. Dynamic Graph Matching
  2.  
  3. Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
  4. Total Submission(s): Accepted Submission(s):
  5.  
  6. Problem Description
  7. In the mathematical discipline of graph theory, a matching in a graph is a set of edges without common vertices.
  8. You are given an undirected graph with n vertices, labeled by ,,...,n. Initially the graph has no edges.
  9. There are kinds of operations :
  10. + u v, add an edge (u,v) into the graph, multiple edges between same pair of vertices are allowed.
  11. - u v, remove an edge (u,v), it is guaranteed that there are at least one such edge in the graph.
  12. 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.
  13.  
  14. Input
  15. The first line of the input contains an integer T(≤T≤), denoting the number of test cases.
  16. In each test case, there are integers n,m(≤n≤,nmod2=,≤m≤), denoting the number of vertices and operations.
  17. For the next m lines, each line describes an operation, and it is guaranteed that u<vn.
  18.  
  19. Output
  20. 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 +.
  21.  
  22. Sample Input
  23.  
  24. +
  25. +
  26. +
  27. +
  28. -
  29. -
  30. +
  31. +
  32.  
  33. Sample Output
  34.  
  35. Source
  36. Multi-University Training Contest
  37.  
  38. Recommend
  39. chendu
  40.  
  41. Statistic | Submit | Discuss | Note

装压dp

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

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

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

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <iostream>
  4. //#include <algorithm>
  5. #include <vector>
  6. using namespace std;
  7. #define ll long long
  8. //#define mod 998244353
  9. const int mod=1e9+;
  10.  
  11. ll dp[<<];//dp[i]:i集合内点完全匹配的方案数
  12. int bit[<<];//i的二进制的1个数;
  13. ll ans[];
  14. int lowbit(int x) {return x&-x;}
  15. int calc(int x)
  16. {
  17. int res=;
  18. while(x){res++;x=x-lowbit(x);}
  19. return res;
  20. }
  21. int main()
  22. {
  23. for(int i=;i<(<<);i++)
  24. bit[i]=calc(i);
  25. int T,n,m,u,v;
  26. char op[];
  27. scanf("%d",&T);
  28. while(T--)
  29. {
  30. scanf("%d%d",&n,&m);
  31. memset(dp,,sizeof dp);
  32. memset(ans,,sizeof ans);
  33. dp[]=;
  34. while(m--)
  35. {
  36. scanf("%s%d%d",op,&u,&v);
  37. u--;v--;
  38. if(op[]=='+')
  39. {
  40. for(int i=(<<n)-;i>;i--)
  41. if(((<<u)&i)&&((<<v)&i))
  42. {
  43. dp[i]+=dp[i-(<<u)-(<<v)];
  44. ans[bit[i]]+=dp[i-(<<u)-(<<v)]; //对于i集合所有点的匹配,会对ans造成的影响
  45. dp[i]=dp[i]%mod;
  46. ans[bit[i]]=ans[bit[i]]%mod;
  47. }
  48. }
  49.  
  50. else
  51. {
  52. for(int i=;i<<<n;i++)
  53. if(((<<u)&i)&&((<<v)&i))
  54. {
  55. dp[i]-=dp[i-(<<u)-(<<v)];
  56. ans[bit[i]]-=dp[i-(<<u)-(<<v)];
  57. dp[i]=(dp[i]+mod)%mod;
  58. ans[bit[i]]=(ans[bit[i]]+mod)%mod;
  59. }
  60. }
  61. for(int i=;i<=n;i=i+)
  62. {
  63. if(i!=)
  64. cout<<" ";
  65. printf("%lld",ans[i]);
  66.  
  67. }
  68. cout<<endl;
  69.  
  70. }
  71.  
  72. }
  73.  
  74. return ;
  75. }

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. 开源搜素引擎:Lucene、Solr、Elasticsearch、Sphinx优劣势比较

    https://blog.csdn.net/belalds/article/details/82667692 开源搜索引擎分类 1.Lucene系搜索引擎,java开发,包括: Lucene Solr ...

  2. WinSDK(菜单笔记)

  3. oracle 死锁

    oracle 死锁 --查用户名,查客户端机器 SELECT distinct s.username,s.MACHINE, s.sid||','||s.serial# FROM gv$session ...

  4. 泛型-----键值对----映射 hashmap--entry中key value 链表

    connection map 集合框架 * java.util.Collection *集合与数组相似,也是可以保存一组元素,并且提供了操作元素的相关方法. *collection是所有集合的顶级接口 ...

  5. 利用ueditor保存到mysql数据库时出现乱码

    首先反复检查页面的字符编码,发现使用的都是 utf-8,再次检查数据库编码格式也用的是UTF-8.用format函数进行格式化,还是不起作用,最用把出现乱码的字段的数据类型由BLOB改成MEDIUMT ...

  6. GoldenGate BR(bounded Recovery)简单说明

    背景 Oracle数据库的在线日志包含已提交的和未提交的事务,但OGG只会将已提交的事务写入到队列文件.因此,针对未提交的事务,特别是未提交的长事务,OGG会怎样处理呢? 有些长事务是在批处理作业中, ...

  7. 外网访问ARM嵌入式Linux系统

    外网访问ARM嵌入式Linux系统 实验室里的ARM嵌入式Linux系统,只能在局域网内访问,怎样从外网也能访问ARM嵌入式Linux系统? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并 ...

  8. Flutter 控件之 Routes 和 Navigator. [PopupRoute]

    一个 App 通常会有多个界面,每个界面实现不同的功能,并在多个界面之间跳转.在 Flutter 中多个界面的跳转是通过 Navigator 来实现的. 在 Flutter 中定义了一个 Overla ...

  9. Luogu P1892 P1525 团伙 关押罪犯

    (怎么都是抓罪犯 怪不得写法差不多) 团伙 关押罪犯 并查集.以"敌人的敌人是朋友"的思路来处理.所以增加一个e/E数组来存储敌人. 关押罪犯还用到了贪心的思路.将冲突值从大到小排 ...

  10. 绑定到外部验证服务LDAP、配置 autofs

    题1:您的系统需要按照以下要求绑定到这个服务上:验证服务器的基本 DN 是: dc=xxxx,dc=xxxx,dc=xxxx. 帐户信息和验证信息都是由 LDAP 提供的.连 接 需 要 使 用 证 ...