A:非常裸的dp。
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int read() { int x=0,f=1;char c=getchar(); while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();} while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } #define P 1000000007 #define N 32 int a,b,c,d,f[N][N][N][N][4]; void inc(int &x,int y){x+=y;if (x>=P) x-=P;} int main() { freopen("count.in","r",stdin); freopen("count.out","w",stdout); a=read(),b=read(),c=read(),d=read(); f[1][0][0][0][0]=f[0][1][0][0][1]=f[0][0][1][0][2]=f[0][0][0][1][3]=1; for (int i=1;i<a+b+c+d;i++) for (int x=0;x<=a;x++) for (int y=0;y<=b;y++) for (int z=0;z<=c;z++) { int t=i-x-y-z; if (t>d) continue; for (int p=0;p<4;p++) for (int q=0;q<4;q++) if (p!=q) { if (q==0&&x<a) inc(f[x+1][y][z][t][q],f[x][y][z][t][p]); if (q==1&&y<b) inc(f[x][y+1][z][t][q],f[x][y][z][t][p]); if (q==2&&z<c) inc(f[x][y][z+1][t][q],f[x][y][z][t][p]); if (q==3&&t<d) inc(f[x][y][z][t+1][q],f[x][y][z][t][p]); } } cout<<((f[a][b][c][d][0]+f[a][b][c][d][1])%P+(f[a][b][c][d][2]+f[a][b][c][d][3])%P)%P; return 0; }