当一个元素增加进来之后,唯一变化的应该是有某一行的长度变长了,那么应该是需要用每一行的长度去
说到底就是不考虑数字放进去的顺序,只考虑状态怎么转移的;再此基础上还要考虑只有知道前面和左边的数字才能安放后面的数字
这里像下面这么写会m掉。但是我看到一个大佬这接在定义的时候限制因为数据不大,所以直接在函数里面定义比如cin>>x; ll dp[x];
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<string.h>
#include<map>
#define ll long long
using namespace std;
int dp[31][31][31][31][31], n, num[6];
int main() {
while (cin >> n) {
memset(num, 0, sizeof(num));
memset(dp, 0, sizeof(dp));
dp[0][0][0][0][0] = 1;
for (int i = 1; i <= n; i++) cin >> num[i];
for (int i = 0; i <= num[1]; i++) {
for (int j = 0; j <= num[2] && j <= i; j++) {
for (int k = 0; k <= num[3] && k <= j; k++) {
for (int l = 0; l <= num[4] && l <= k; l++) {
for (int m = 0; m <= num[5] && m <= l; m++) {
if (i + 1 <= num[1]) dp[i + 1][j][k][l][m] += dp[i][j][k][l][m];
if (j + 1 <= num[2] && j + 1 <= i) dp[i][j + 1][k][l][m] += dp[i][j][k][l][m];
if (k + 1 <= num[3] && k + 1 <= j) dp[i][j][k + 1][l][m] += dp[i][j][k][l][m];
if (l + 1 <= num[4] && l + 1 <= k) dp[i][j][k][l + 1][m] += dp[i][j][k][l][m];
if (m + 1 <= num[5] && m + 1 <= l) dp[i][j][k][l][m + 1] += dp[i][j][k][l][m];
}
}
}
}
}
cout << dp[num[1]][num[2]][num[3]][num[4]][num[5]] << endl;
}
return 0;
}