# HDU 4779-Tower Defense-组合数学-[解题报告]HOJ

2016-03-14 15:06:27来源:[db:出处]作者:[db:作者]人点击

Tower Defense

DRD loves playing computer games, especially Tower Defense games. Tower Defense is a famous computer game with a number of variations. In general, you are to build some defense towers to guard your territory in this game. 　　However, in most Tower Defense games, your defending towers will not attack each other. You will see the shells flying through your towers and finally hit the target on your screen. DRD thinks it to be absurd, and he designed a new tower defense game.　　In DRD’s game, you have two kinds of defending tower, heavy tower and light tower. You can put the tower on a grid with N rows and M columns and each cell in the grid can hold one tower at most. Both two kinds of towers can attack the cells in the same column or the same row as it is located in, and your towers may attack each other. Moreover, light towers should not be attacked by other towers while heavy towers can be attacked by at most one other tower.　　You can put some of your towers (at least one tower) in the grid to build a tower formation satisfying the restriction above. And now, DRD wants you to calculate that how many different tower formations could be designed. Note that all the towers of the same type are considered to be identical. While the answer could be quite large, you should output the number mod (109 + 7).

There are multiple test cases in the input. The first line of the input file is an integer T demonstrating the number of test cases. (0< T<= 200).　　For each test case, there is only one line containing 4 integers, N, M, P and Q ,meaning that the grid has N rows and M columns, and you have P heavy towers and Q light towers. You do not have to put all the towers in the grid. (1 <= N, M <= 200, 0 <= P, Q <= 200)

There are multiple test cases in the input. The first line of the input file is an integer T demonstrating the number of test cases. (0< T<= 200).　　For each test case, there is only one line containing 4 integers, N, M, P and Q ,meaning that the grid has N rows and M columns, and you have P heavy towers and Q light towers. You do not have to put all the towers in the grid. (1 <= N, M <= 200, 0 <= P, Q <= 200)

32 2 0 12 2 2 03 3 2 1

410144

hdu 4779 Tower Defense

#include #include #include #include #include using namespace std;#pragma comment(linker, "/STACK:1024000000,1024000000") typedef __int64 ll;const int MAXN = 205;const ll mod = 1000000007;ll AA[MAXN], CC[MAXN][MAXN], POW[MAXN], CM[MAXN][MAXN];ll niyuan(ll a){ ll res = 1, p = a; int n = mod-2; while (n) { if (n & 1) res = res*p%mod; p = p*p%mod; n >>= 1; } return res;}void init(){ int j, i, k; for (AA[0] = 1, i = 1; i<= 200; ++i) AA[i] = AA[i-1]*i%mod; for (POW[0] = 1, i = 1; i<= 200; ++i) POW[i] = POW[i-1]*2%mod; CC[0][0] = 1; CM[0][0] = 1; for (i = 1; i<= 200; ++i) { for ( j = 0, k=i/2+1; j