记录编号 149999 评测结果 AAAAAAAAAA
题目名称 [Violet 1] 木偶 最终得分 100
用户昵称 Gravatar一個人的雨 是否通过 通过
代码语言 C++ 运行时间 0.006 s
提交时间 2015-02-27 12:11:36 内存使用 0.31 MiB
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 55;
int n, a[N], f[N];

 inline int read(){
 int x = 0, sgn = 1;
 char ch = getchar();
  while (ch < '0' || ch > '9')
    {
     if (ch == '-') sgn = -1;
      ch = getchar();
    }
  while (ch >= '0' && ch <= '9')
     {
     x = x * 10 + ch - '0';
        ch = getchar();
     }
     return sgn * x;
 
 }
   int calc(int x, int y){
     int i, k;
     for (k = 1; k <= y - x + 1; ++k){
         for (i = k; i <= y - x; ++i)
             if (abs(a[i + x] - a[i + x - k]) > 1) return k - 1;
         if (abs(a[x + k - 1] - a[y - k + 1]) <= 1) return k - 1;
     }
     return y - x + 1; }
  
 int main(){
 	 freopen("puppet.in","r",stdin);
	 freopen("puppet.out","w",stdout); 
     int i, j;
     while (scanf("%d", &n) != EOF){
         for (i = 1; i <= n; ++i)
             scanf("%d", a + i);
         sort(a + 1, a + n + 1);
         memset(f, 0, sizeof(f));
         for (i = 1; i <= n; ++i)
             for (j = 0; j < i; ++j)
                 f[i] = max(f[i], f[j] + calc(j + 1, i));
         printf("%d\n", f[n]);
     }
     return 0;
 }