AcWing 317. 陨石的秘密

1 -> {}
2 -> []
3 -> ()

\(f[d][a][b][c]\)
表示 \([i * 2 - 1, j * 2]\) 这段区间 深度为 d
\(1\)\(a\) 个, \(2\)\(b\) , \(3\)\(c\)

初始状态
\(f[1][0][0][1] = 1;\)
\(f[1][0][1][0] = 1;\)
\(f[1][1][0][0] = 1;\)

操作1:用 () 括起来
需满足: \(a = 0\)\(b = 0\)
\(f[d][a][b][c] += f[d - 1][a][b][c - 1]\)

操作2:用 [] 括起来
需满足:\(a = 0\)
\(f[d][a][b][c] += f[d - 1][a][b - 1][c]\)

操作3:用 {} 括起来
\(f[d][a][b][c] += f[d - 1][a - 1][b][c]\)

合并 (枚举第一个括号)

#include <cstdio>
#include <iostream>
using namespace std;
const int S = 35, L = 11, P = 11380;
int L1, L2, L3, D, f[S][L][L][L], s[S][L][L][L];
int main() {
	scanf("%d%d%d%d", &L1, &L2, &L3, &D);
	s[0][0][0][0] = f[0][0][0][0] = 1;
	for (int d = 1; d <= D; d++) {
		for (int a = 0; a <= L1; a++) {
			for (int b = 0; b <= L2; b++) {
				for (int c = 0; c <= L3; c++) {
					if (a) (f[d][a][b][c] += f[d - 1][a - 1][b][c]) %= P;
					else if(b) (f[d][a][b][c] += f[d - 1][a][b - 1][c]) %= P;
					else if(c) (f[d][a][b][c] += f[d - 1][a][b][c - 1]) %= P;
					
					for (int a1 = 0; a1 <= a; a1++) {
						for (int b1 = 0; b1 <= b; b1++) {
							for (int c1 = 0; c1 <= c; c1++) {
								if (a1 + b1 + c1 == 0) continue;
								if (a1 + b1 + c1 == a + b + c) continue;
								if (a1) {
									if (d >= 2) (f[d][a][b][c] += s[d - 2][a1 - 1][b1][c1] * f[d][a - a1][b - b1][c - c1]) %= P;
									(f[d][a][b][c] += f[d - 1][a1 - 1][b1][c1] * s[d][a - a1][b - b1][c - c1]) %= P;
								} else if (b1) {
									if (d >= 2) (f[d][a][b][c] += s[d - 2][a1][b1 - 1][c1] * f[d][a - a1][b - b1][c - c1]) %= P;
									(f[d][a][b][c] += f[d - 1][a1][b1 - 1][c1] * s[d][a - a1][b - b1][c - c1]) %= P;
								} else {
									if (d >= 2) (f[d][a][b][c] += s[d - 2][a1][b1][c1 - 1] * f[d][a - a1][b - b1][c - c1]) %= P;
									(f[d][a][b][c] += f[d - 1][a1][b1][c1 - 1] * s[d][a - a1][b - b1][c - c1]) %= P;
								}
							}
						}
					}
					s[d][a][b][c] = (s[d - 1][a][b][c] + f[d][a][b][c]) % P;
				}
				
			}
		}
	}
	printf("%d\n", f[D][L1][L2][L3]);
	return 0;
}
posted @ 2020-02-28 21:37  DMoRanSky  阅读(135)  评论(0编辑  收藏  举报