Problem Description
One day, Harry got a magical box. The box is made of n*m grids. There are sparking jewel in some grids. But the top and bottom of the box is locked by amazing magic, so Harry can’t see the inside from the top or bottom. However, four sides of the box are transparent,
so Harry can see the inside from the four sides. Seeing from the left of the box, Harry finds each row is shining(it means each row has at least one jewel). And seeing from the front of the box, each column is shining(it means each column has at least one
jewel). Harry wants to know how many kinds of jewel’s distribution are there in the box.And the answer may be too large, you should output the answer mod 1000000007.
Input
There are several test cases.
For each test case,there are two integers n and m indicating the size of the box.
0≤n,m≤50.
Output
For each test case, just output one line that contains an integer indicating the answer.
Sample Input
1 1
2 2
2 3
Sample Output
1
7
25
容斥+組合知識:感謝凡神寫的題解點擊打開鏈接我們首先要保證的是每行都有1,這是前提。然後要想得到答案我們可以枚舉i列全為0(共有C(m,i)選法),然後就是考慮每行還剩的(m-i)個位置,我們此時可以隨意放置01(2^(m-i)方法),但是為了保證每行都有1故要減1,此時為(2^(m-i)-1).然後有n行,所以sum[i]=(2^(m-i)-1)^n,然後我們要從裡面剔除一些東西,就是僅僅第i列全為0(注意剛剛i列全為不是僅僅)所以要容斥。ans=sum[0]-sum[1]+sum[2]..#include
#include
#include
#include
#include
#include
#include
#include
#include
DP寫法:我們考慮dp[i][j]:表示前i行前j列都有1的方案數。dp[i][k]+=dp[i-1][j]*c[m-j][k-j]*c[j][t-(k-j)].t:表示i行選幾個。#include
#include
#include
#include
#include
#include
#include
#include
#include