Stoi is Shantou oi ... Bored turned to last year's game title, wrote and then measured himself.
In fact, I really want to spit groove Why the title is Perm,perm seems to have nothing to do with the partner.
DP (x,s) =∑DP (X-1,s-{i}) (0<=i<n and I-Girl and X-Boys are friends), DP (X,S) indicates that the first X boys have paired up with a girl, paired with a female in set S. Border: Number No. 0 Male and Female no. I (0<=i<n), if friend DP (0,{i}) = 1; DP (0,{i}) =0. The side-by-side mod in the calculation process, the final output is OK.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineRep (i,r) for (int i=0;i<r;i++)#defineCLR (x,c) memset (x,c,sizeof (x))using namespacestd;Const intmaxn= -+5;intMod,n;intOK[MAXN][MAXN];intd[maxn][1<< -];intdpintXints) {int&ans=D[x][s]; if(ans>=0)returnans; Ans=0; Rep (I,n)if(Ok[x][i] && (S & (1<<i)) (Ans+=DP (x1, s^ (1<<i))%=MoD; returnans;}intMain () {Freopen ("perm.in","R", stdin); Freopen ("Perm.out","W", stdout); CLR (OK,0); CLR (d,-1); CIN>>n>>MoD; Rep (I,n) Rep (j,n) scanf ("%d",&Ok[i][j]); Rep (I,n)if(ok[0][i]) d[0][1<<i]=1; Elsed[0][1<<i]=0; cout<<DP (n1,(1<<n)-1) <<Endl; return 0;}
View Code
[STOI2014] Partner (DP)