[STOI2014] partner (dp), stoi2014 partner dp
STOI is Shantou OI... I was bored with turning to the question of last year's competition. I wrote it and tested it myself. In fact, I really want to tell you why the subject name is perm. perm seems to have nothing to do with the partner ..
Dp (x, s) = Σ dp (x-1, s-{I}) (0 <= I <n, I ε s, girls I and boys x are friends. dp (x, s) indicates that the first x boys have been paired with girls, and those who have been paired with girls are represented by a collection of s. Boundary: Boys 0th and girls I (0 <= I <n). If you are a friend, dp (0, {I}) = 1; otherwise, dp (0, {I}) = 0. in the calculation process, the edge is calculated and mod, and the final output is OK.
----------------------------------------------------------------------------
# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define rep (I, r) for (int I = 0; I <r; I ++) # define clr (x, c) memset (x, c, sizeof (x) using namespace std; const int maxn = 20 + 5; int mod, n; int OK [maxn] [maxn]; int d [maxn] [1 <20]; int dp (int x, int s) {int & ans = d [x] [s]; if (ans> = 0) return ans; ans = 0; rep (I, n) if (OK [x] [I] & (s & (1 <I) (ans + = dp (x-1, s ^ (1 <I ))) % = mod; return ans;} int main () {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; else d [0] [1 <I] = 0; cout <dp (n-1, (1 <n) -1) <endl; return 0 ;}
Bytes ------------------------------------------------------------------------------------