先写了个next_permutation结果T了,于是开始写状压 设f[s][i]为选取状态为s,选的数模d为i的方案数,去重的话直接除以每个数字的出现次数的阶乘即可 #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=20; int T,d,n,a[N],fac[N],c[N],f[2005][2005]; char s[N]; int main(…
Iahub wants to meet his girlfriend Iahubina. They both live in Ox axis (the horizontal axis). Iahub lives at point 0 and Iahubina at point d. Iahub has n positive integers a1, a2, ..., an. The sum of those numbers is d. Suppose p1, p2, ..., pn is a p…
正难则反,设g[s]为集合s不一定联通的方案数,这个很好求,把边数+1乘起来即可,f[s]为s一定联通的方案数 f考虑容斥,就是g[s]-Σf[nw]*g[s^nw],nw是s的子集,这样就减掉了不联通的情况 这个枚举子集的方法还挺巧的-- #include<iostream> #include<cstdio> using namespace std; const int N=20,mod=1000000007; int n,c[N][N],a[N],tot,f[100005],g…