It's easy to think of the principle of repulsion, and here's a little trick of using a binary number to represent the intersection of a set.
1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 6typedefLong Longll;7 Const intMOD =1000007;8 Const intN =501;9 intCn[n][n];Ten One voidInit () A { -Memset (CN,0,sizeof(CN)); -cn[0][0] =1; the for(inti =1; i < N; i++ ) - { -cn[i][0] = Cn[i][i] =1; - for(intj =1; J < I; J + + ) + { -CN[I][J] = (Cn[i-1][J] + cn[i-1][j-1] ) %MOD; + } A } at } - - intMain () - { - init (); - intT; inCIN >>T; - for(int_case =1; _case <= t; _case++ ) to { + intN, M, K; -CIN >> n >> M >>K; the intAns = cn[n *m] [K]; * for(ints =1; s < -; s++ ) $ {Panax Notoginseng intCNT =0, r = N, c =m; - for(inti =0; I <4; i++ ) the { + if(S & (1<<i)) A { thecnt++; + if(I &1 ) - { $r--; $ } - Else - { thec--; - }Wuyi } the } - if(CNT &1 ) Wu { -Ans = (Ans-cn[r * c][k] + MOD)%MOD; About } $ Else - { -Ans = (ans + cn[r * c][k])%MOD; - } A } +cout <<" Case"<< _case <<": "<< ans <<Endl; the } - return 0; $}
UVA 11806 repulsion principle + binary