#include <bits/stdc++.h>
#define N 100
using namespace std;
int n;
int f[N], ai[N];
int g[N][N];
int main()
{
while (scanf("%d", &n) !=EOF)
{
for (int i = 1; i <= n; ++ i) scanf("%d", &ai[i]);
sort(ai + 1, ai + n + 1);
for (int i = 1; i <= n; ++ i)
for (int j = i; j <= n; ++ j)
{
int bo = 1;
for (int k = 1; k <= j - i + 1; ++ k)
{
int p, q;
for (p = i, q = i + k; q <= j; ++ p, ++ q)
if (ai[q] - ai[p] > 1) bo = 0;
if (abs(ai[p] - ai[i + k - 1]) <= 1) bo = 0;
if (!bo) {g[i][j] = k - 1; break;}
}
if (bo) g[i][j] = j - i + 1;
//if (g[i][j] != cal(i, j))
// puts("haha");
}
for (int i = 1; i <= n; ++ i) f[i] = 0;
for (int i = 1; i <= n; ++ i)
for (int j = 0; j < i; ++ j)
f[i] = max(f[i], f[j] + g[j + 1][i]);
printf("%d\n", f[n]);
}
}
12708:[Violet 1]木偶
最新推荐文章于 2024-09-04 21:39:45 发布