**Zoj 3687 the review plan I)**

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;#define CLR( a, b ) memset( a, b, sizeof(a) )#define MOD 55566677#define MAXN 55LL fac[MAXN], res;int n, m, row[MAXN], col[MAXN], g[MAXN][2], hash[MAXN][MAXN] ;void init(){ fac[0] = 1; for( int i = 1; i < MAXN; ++i ) fac[i] = ( fac[i-1] * i ) % MOD;}void dfs( int id, int num ){ if( id > m ) { if( num & 1 ) res = ( ( res - fac[ n - num ] ) % MOD + MOD ) % MOD; else res = ( res + fac[ n - num ] ) % MOD; return; } dfs( id + 1, num ); if( row[g[id][0]] == 0 && col[g[id][1]] == 0 ) { row[g[id][0]] = col[g[id][1]] = 1; dfs( id + 1, num + 1 ); row[g[id][0]] = col[g[id][1]] = 0; } }int main(){ init(); while( ~scanf( "%d %d", &n, &m ) ) { CLR( row, 0 ), CLR( col, 0 ), CLR( hash, 0 ); for( int i = 1; i <= m; ++i ) { scanf( "%d %d", &g[i][0], &g[i][1] ); if( hash[g[i][0]][g[i][1]] ) { --i; --m; } else hash[g[i][0]][g[i][1]] = 1; } res = 0; dfs( 1, 0 ); res = ( res % MOD + MOD ) % MOD; printf( "%lld\n", res ); } return 0;}

Violent search for learning

# Include <cstdio> # include <cstring> typedef long ll; # define CLR (a, B) memset (a, B, sizeof ()) # define maxn 55 # define mod 55566677ll FAC [maxn], C [maxn] [maxn], R [maxn], R [maxn], Res; bool vis_r [maxn], vis_c [maxn], hash [maxn] [maxn]; int n, m, H [maxn], V [maxn], one, X, Y; void Init () // recursively initialize the formula {FAC [0] = 1; for (INT I = 1; I <maxn; ++ I) FAC [I] = (FAC [I-1] * I) % MOD; For (INT I = 0; I <maxn; ++ I) C [I] [I] = C [I] [0] = 1; for (INT I = 2; I <maxn; ++ I) {for (Int J = 1; j <I; ++ J) {c [I] [J] = C [I-1] [J] + C [I-1] [J-1]; if (C [I] [J]> = mod) C [I] [J]-= mod ;}} void DFS (int K, int ID) {If (k> N) return; For (INT I = ID; I <n; ++ I) {for (Int J = 0; j <n; ++ J) {If (! Vis_r [I] &! Vis_c [J] & hash [I] [J]) {R [k] ++; If (R [k]> = mod) R [k]-= MOD; vis_r [I] = vis_c [J] = true; DFS (k + 1, I); vis_r [I] = vis_c [J] = false ;}}}} void CAL () {CLR (R, 0); R [0] = 1; R [1] = m; For (INT I = 2; I <= N; ++ I) {for (Int J = 0; j <= one & J <= I; ++ J) {R [I] + = R [I-j] * C [one] [J]; R [I] % = mod ;}} ll solve () {ll ans = FAC [N]; ll K =-1; for (INT I = 1; I <= N; ++ I) {ans + = K * fac [N-I] * R [I]; K * =-1;} ans = (ANS % mod + mod) % MOD; return ans;} int main () {Init (); While (~ Scanf ("% d", & N, & M) {CLR (H, 0); CLR (v, 0); CLR (R, 0 ); CLR (hash, false); CLR (vis_r, false); CLR (vis_c, false); For (INT I = 0; I <m; ++ I) {scanf ("% d", & X, & Y); X --; y --; If (hash [x] [Y]) {I --; m --; continue;} H [x] ++; V [y] ++; hash [x] [Y] = 1;} One = 0; For (INT I = 0; I <n; ++ I) {for (Int J = 0; j <n; ++ J) {If (hash [I] [J] & (H [I] <= 1 & V [J] <= 1 )) {hash [I] [J] = false; one ++ ;}} R [0] = 1; DFS (1, 0); CAL (); printf ("% LLD \ n", solve ();} return 0 ;}

Prohibited bit Arrangement

Zoj 3687 the review plan I)