【hdu 6321】Dynamic Graph Matching
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
DP
设f[i][j]表示前i个操作,已经匹配了的点的状态集合为j的方案数
对于+操作
有两种情况。
1.这条边作为匹配的边
2.这条边没有作为匹配边
f[i][j] = f[i-1][j-(u,v)] + f[i-1][j]
作为匹配边,转化一下就是这条边的两个点连上了。也即被匹配了。
对于-操作
考虑前i-1个操作。
会发现+操作的先后顺序不影响前i-1个操作之后的结果。
因此我们干脆就认为第i-1个操作就是和- u,v对应的+ u,v就好了
因此我们只需将$f[i-1][j]-f[i-1][j-(u,v)]$的值赋值给f[i][j]即可。
最后统计匹配数的方案就好了
j这个状态有几个匹配要预处理出来。
【代码】
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define inf 2099999999
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep1(i,a,b) for(int i=a;i>=b;i--)
const int M = 1024;
int T,n,m;
int f[M+10],pre[12];
int cnt[6],pre2[M+10];
char s[5];
int main()
{
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
scanf("%d",&T);
pre[0] = 1;
rep(i,1,10) pre[i] = pre[i-1]*2;
for (int i = 0;i < M;i++){
int x = i,cur = 0;
while (x>0){
cur+=(x%2);
x/=2;
}
if (cur%2==0) pre2[i] = cur/2;
}
while(T--){
scanf("%d%d",&n,&m);
memset(f,0,sizeof f);
f[0] = 1;
for (int i = 1;i <= m;i++){
int x,y;
scanf("%s",s);scanf("%d%d",&x,&y);
x--;y--;
if (s[0]=='+'){
for (int j = pre[n]-1;j >=0;j--)
if (((j&pre[x])>0) && ((j&pre[y])>0) ){
int jj = j ^ pre[x];
jj = jj ^ pre[y];
f[j] = f[j] + f[jj];
if (f[j]>mod) f[j]-=mod;
}
}else{
for (int j = pre[n]-1;j >= 0;j--){
if (((j&pre[x])>0) && ((j&pre[y])>0)){
int jj = j^pre[x];
jj = jj^pre[y];
f[j] = f[j]-f[jj]+mod;
if (f[j]>mod) f[j]-=mod;
}
}
}
memset(cnt,0,sizeof cnt);
for (int j = 0;j < pre[n];j++)
cnt[pre2[j]] = (cnt[pre2[j]] + f[j])%mod;
for (int i = 1;i <= n/2;i++) {
if (i!=1) putchar(' ');printf("%d",cnt[i]);
}
puts("");
}
}
return 0;
}
【hdu 6321】Dynamic Graph Matching的更多相关文章
- 【Sichuan 2017D】Dynamic Graph
题意 300个点的无环图,开始都是白色,每次改变某个节点的颜色(黑/白),问有多少对白点之间存在只有白点的路径. 题解 类似floyd,求出两点之间的路径条数.然后白到黑就删去对应路径,黑到白就增加对 ...
- HDU 6321 Dynamic Graph Matching
HDU 6321 Dynamic Graph Matching (状压DP) Problem C. Dynamic Graph Matching Time Limit: 8000/4000 MS (J ...
- HDU6321 Dynamic Graph Matching【状压DP 子集枚举】
HDU6321 Dynamic Graph Matching 题意: 给出\(N\)个点,一开始没有边,然后有\(M\)次操作,每次操作加一条无向边或者删一条已经存在的边,问每次操作后图中恰好匹配\( ...
- hdu多校第3场C. Dynamic Graph Matching
Problem C. Dynamic Graph Matching Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Tot ...
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
随机推荐
- 【codeforces 716D】Complete The Graph
[题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...
- 2015 Multi-University Training Contest 8 hdu 5381 The sum of gcd
The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Struts2校验
struts2校验有两种实现方法: 手工编写代码实现(基本验证) //login.jsp <font color="red"><s:fielderror/> ...
- 关于excel导入、导出(POI)
当前B/S模式已成为应用开发的主流,而在企业办公系统中,常常有客户这样子要求:你要把我们的报表直接用Excel打开(电信系统.银行系统).或者是:我们已经习惯用Excel打印.这样在我们实际的开发中, ...
- 解决VTune错误PMU resources currently being used by another profiling tool or process
错误信息: When I ran Hardware Event-based Sampling Analysis 0, it showed the ERROR: Collection failed Co ...
- ios假设写一个提示带动画的View,能够来引导用户行为
先上图: 这个UIView能够这样写: -(id)initWithFrame:(CGRect)frame backImage:(UIImage*)image msgStr:(NSString*)txt ...
- C++实现位数组
当我们遇到大量整数排序时候为了节省内存空间我们能够考虑使用bit数组来实现,缺点是其仅仅适用于正整数. 思想: 在32位系统一个int类型占4个字节,按位来计算一个int类型能够记录32个数.因此,採 ...
- Qt容器类的对象模型及应用(线性结构篇:对于QList来说,sharable默认是false的,但对于接下来讲的QVector来说,sharable默认是true)
用Qt做过项目开发的人,肯定使用过诸如QList.QVector.QLinkList这样的模板容器类,它们虽然名字长的不同,但使用方法都大致相同, 因为其使用方法都大体相同,很多人可能随便拿一个容器类 ...
- SQL Server loop - how do I loop through a set of records
SQL Server loop - how do I loop through a set of records By using T-SQL and cursors like this : DECL ...
- 【POJ 2182】Lost Cows
[题目链接] http://poj.org/problem?id=2182 [算法] 树状数组 + 二分 [代码] #include <algorithm> #include <bi ...