Problem C. Dynamic Graph Matching

题意:起初有n(n保证是偶数)个点,现在有m次操作,每次操作可以选择删除或添加一些边,要求输出每次操作后, 匹配数为1,2,3,4 --- n/2 的方案数

思路: 当添加u---v边时,对于包含了u,v的所有可行状态都多了dp[S-u-v]种方案数(u,v连u--v这条边)

#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<queue>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e7+7;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
    char c; int sgn; T bit=0.1;
    if(c=getchar(),c==EOF) return 0;
    while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
    sgn=(c=='-')?-1:1;
    ret=(c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
    if(c==' '||c=='\n'){ ret*=sgn; return 1; }
    while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
    ret*=sgn;
    return 1;
}
ll dp[1<<15];
ll ans[500];
int bit[1<<15];
void mian(){
    int n,m;
    sf(n),sf(m);
    dp[0]=1;
    while(m--){
        char op[3],u,v;
        scanf("%s",op);sf(u);sf(v);
        --u,--v;  /// 状压方便表示
        for(int i=(1<<n);i>=1;--i){
            if(((1<<u)&i)==0 || ((1<<v)&i)==0 ) continue;
            ll det=dp[i-(1<<u)-(1<<v)];
            if(op[0]=='+'){
                dp[i]+=det;
                dp[i]%=MOD;
                ans[bit[i]]+=det;
                ans[bit[i]]%=MOD;
            }
            else{
                dp[i]-=det;
                dp[i]%=MOD;
                dp[i]+=MOD;
                dp[i]%=MOD;
                ans[bit[i]]-=det;
                ans[bit[i]]%=MOD;
                ans[bit[i]]+=MOD;
                ans[bit[i]]%=MOD;
            }
        }
        for(int i=2;i<=n;i+=2) printf("%d%c",ans[i],i==n?'\n':' ');
    }
}
int cul(int x){
    int ans=0;
    while(x){
        if(x%2==1)  ans++;
        x/=2;
    }
    return ans;
}
void init(){
    for(int i=1;i<=(1<<12);++i){
        bit[i]=cul(i);
    }
}

int main(void){
    init();
    int T;
    sf(T);
    while(T--){
        memset(dp,0,sizeof dp);
        memset(ans,0,sizeof ans);
        mian();
    }

    return 0;
}