[STOI2014] Partner (DP)

Source: Internet
Author: User

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&LT;&LT;DP (n1,(1<<n)-1) <<Endl; return 0;}
View Code

[STOI2014] Partner (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.