xfstart07
Get busy living or get busy dying

#include < fstream >
using   namespace  std;

int  n,m;
int  a[ 101 ];
int  f[ 101 ][ 101 ];
int  cmp( const   void *  no1, const   void *  no2){
    
return   * ( int   * )no1 -* ( int * )no2;
}
int  main()
{
    ifstream cin(
" chop.in " );
    ofstream cout(
" chop.out " );
    cin
>> n >> m; m += 3 ;
    
for ( int  i = 1 ;i <= n; ++ i) 
        cin
>> a[i];
    qsort(a
+ 1 ,n, sizeof ( int ),cmp);
    memset(f,
0x7F , sizeof (f));
    f[
0 ][ 0 ] = 0 ;
    
for ( int  i = 1 ;i <= n; ++ i)
        
for ( int  j = 1 ;j <= i / 2 ; ++ j){
            f[i][j]
= f[i - 1 ][j];
            
if (f[i][j] > f[i - 2 ][j - 1 ] + (a[i] - a[i - 1 ]) * (a[i] - a[i - 1 ]))
                f[i][j]
= f[i - 2 ][j - 1 ] + (a[i] - a[i - 1 ]) * (a[i] - a[i - 1 ]);
        }
    
if (f[n][m] < 0xFFFFFF )
        cout
<< f[n][m] << endl;
    
else  
        cout
<<- 1 << endl;
    
return   0 ;
}




posted on 2009-04-19 17:04 xfstart07 阅读(186) 评论(0)  编辑 收藏 引用 所属分类: 代码库

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理