# 【BZOJ3167】[HEOI2013]SAO（动态规划）

## 题解

for i:=1 to x do
for k:=1 to y do
for j:=k to y do
f[u][i+j]+=f[u][i]*f[v][k]*C[i+j-1][i-1]*C[x+y-i-j][x-i]

for i:=1 to x do
for j:=1 to y do
for k:=1 to j do
f[u][i+j]+=f[u][i]*f[v][k]*C[i+j-1][i-1]*C[x+y-i-j][x-i]

for i:=1 to x do
for k:=1 to y do
for j:=0 to k-1 do
f[u][i+j]+=f[u][i]*f[v][k]*C[i+j-1][i-1]*C[x+y-i-j][x-i]

for i:=1 to x do
for j:=0 to y do
for k:=i+1 to y do
f[u][i+j]+=f[u][i]*f[v][k]*C[i+j-1][i-1]*C[x+y-i-j][x-i]

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MOD 1000000007
#define MAX 1010
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
struct Line{int v,next,w;}e[MAX<<1];
int h[MAX],cnt;
inline void Add(int u,int v,int w){e[cnt]=(Line){v,h[u],w};h[u]=cnt++;}
void init(){memset(h,0,sizeof(h));cnt=1;}
int n,C[MAX][MAX];char ch[2];
int f[MAX][MAX],sz[MAX],tmp[MAX];
void dfs(int u,int ff)
{
f[u][1]=1;sz[u]=1;
for(int i=h[u];i;i=e[i].next)
{
int v=e[i].v;if(v==ff)continue;
dfs(e[i].v,u);
for(int a=1;a<=sz[u];++a)
for(int b=0;b<=sz[v];++b)
if(e[i].w)
else
sz[u]+=sz[v];
for(int j=1;j<=sz[u];++j)f[u][j]=tmp[j],tmp[j]=0;
}
}
int main()
{
for(int i=0;i<MAX;++i)C[i][0]=1;
for(int i=1;i<MAX;++i)
for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
while(T--)
{