题解,AC的
2023-07-17 10:39:34
发布于:广东
2阅读
0回复
0点赞
#include <cstdio>
using namespace std;
const int max_n = 50;
int dp[max_n][max_n][max_n+1][max_n+1] = {}, a[max_n];
void upd(int& a, int b) { a = ((a > b)? a:b); }
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", a + i);
for (int i = 0; i < n; i++)
for (int j = 1; j <= a[i]; j++)
for (int k = a[i]; k <= max_n; k++)
dp[i][i][j][k] = 1;
for (int l1 = 2; l1 <= n; l1++)
for (int l = 0, r = l1 - 1; r < n; l++, r++)
for (int l2 = 1; l2 <= max_n; l2++)
for (int lp = 1, rp = l2; rp <= max_n; lp++, rp++)
{
if (lp != max_n)
upd(dp[l][r][lp][rp], dp[l][r][lp+1][rp]);
upd(dp[l][r][lp][rp], dp[l][r][lp][rp-1]);
upd(dp[l][r][lp][rp], dp[l+1][r][lp][rp] + (lp == a[l]));
upd(dp[l][r][lp][rp], dp[l][r-1][lp][rp] + (rp == a[r]));
upd(dp[l][r][lp][rp], dp[l+1][r-1][lp][rp] + (lp == a[r]) + (rp == a[l]));
}
printf("%d\n", dp[0][n-1][1][max_n]);
return 0;
}
这里空空如也
有帮助,赞一个