[STOI2014] partner (dp), stoi2014 partner dp

Source: Internet
Author: User

[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 ------------------------------------------------------------------------------------
 

 

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.