Title Description
In \ (n * m \) every row in each column of the matrix has a diamond, ask the kind of diamond distribution?
The answer there may be large, the output answer to \ (1000000007 \) modulo.
Input
For each test case, there are two integers \ (n-\) and \ (m \) represents the size of the box. \ (0 <N, M < 50 \)
Output
The number of output distribution of each data.
Sample Input
1 1
2 2
2 3
Sample Output
1
7
25
This is a relatively good inclusion and exclusion problems.
First, it is clear that we see the \ (n, m \) range is not great, considering \ (dp \) .
Defined \ (dp [i] [j ] \) expressed (I \) \ row and \ (J \) column of the program number of conditions have been met.
As for why there is a \ (i \) line and \ (j \) column, rather than the former \ (i \) line and \ (j \) column, because before the corresponding \ (i \) line, there \ (i \) line will be simpler, better demand.
After seeking direct inclusion and exclusion can be.
With the following definitions we can directly start vigorously \ (dp \) a.
For the currently considered \ (I \) row \ (J \) column, if not total, consider placing a diamond \ (2 ^ {i * j } \) are emulated.
And now we need to which the program does not meet the conditions to be removed.
For \ (i \) line \ (j \) column, we need to get rid of less than \ (i \) line \ (j \) column, and we \ (dp \) is from small to large pieces cited.
So, when we ask \ (dp [i] [j ] \) when, \ (dp [i-1] [J] ... \) , etc. \ (dp \) value we have been seeking out.
And the \ (I \) row \ (J \) scheme column to remove \ (A \) line \ (B \) of program is not that the \ (I \) row \ (J \) column select \ ( a \) line \ (b \) column you?
Rows and columns can be separated to count, i.e. from \ (I \) row \ (J \) column select \ (A \) line \ (B \) Number Scheme column = from \ (I \) selected row \ (A \) the number of program lines from * \ (j \) column select \ (b \) the number of program columns.
That \ (C (I, A) * C (n-, J) \) .
Similarly, we enumerate all less than or equal \ ((i, j) \ ) of points, but these conditions are not satisfied minus the program just fine.
Note that to add negative then modulo the modulus
code show as below
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define int long long
#define reg register
#define Raed Read
#define clr(a,b) memset(a,b,sizeof a)
#define Mod(x) (x>=mod)&&(x-=mod)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)>(b)?(b):(a))
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,G,x) for(int i=(G).Head[x]; i; i=(G).Nxt[i])
#pragma GCC target("avx,avx2,sse4.2")
#pragma GCC optimize(3)
inline int Read(void) {
int res=0,f=1;
char c;
while(c=getchar(),c<48||c>57)if(c=='-')f=0;
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>=48&&c<=57);
return f?res:-res;
}
template<class T>inline bool Min(T &a, T const&b) {
return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a, T const&b) {
return a<b?a=b,1:0;
}
const int N=55,M=1e5+5,mod=1e9+7;
bool MOP1;
int n,m,Fac[N],Inv[N],V[N],Pow[N*N],dp[N][N];
int C(int a,int b) {
return ((Fac[a]*Inv[a-b])%mod*Inv[b])%mod;
}
bool MOP2;
inline void _main(void) {
Fac[0]=Inv[0]=Fac[1]=V[1]=Inv[1]=Pow[0]=1ll;
rep(i,2,50) {
Fac[i]=(Fac[i-1]*i)%mod;
V[i]=(mod-mod/i)*V[mod%i]%mod;
Inv[i]=(Inv[i-1]*V[i])%mod;
}
rep(i,1,2500)Pow[i]=Pow[i-1]*2ll%mod;
rep(i,0,50)rep(j,0,50) {
dp[i][j]=Pow[i*j];
rep(a,0,i)rep(b,0,j) {
if(a==i&&b==j)continue;
dp[i][j]=(dp[i][j]-((dp[a][b]*C(i,a))%mod*C(j,b))%mod)%mod;
}
dp[i][j]=(dp[i][j]+mod)%mod;
}
while(~scanf("%lld %lld",&n,&m)) {
printf("%lld\n",dp[n][m]);
}
}
signed main() {
_main();
return 0;
}