xfstart07
Get busy living or get busy dying

题解

#include < fstream >
using   namespace  std;

int  n,m;
int  s[ 16 ];
long   long  f[ 17 ][ 17 ];
int  main()
{
    ifstream cin(
" bigexp.in " );
    ofstream cout(
" bigexp.out " );
    cin
>> n >> m;
    
for ( int  i = 1 ;i <= m; ++ i)
        
for ( int  j = 1 ;j <= n; ++ j)
            f[i][j]
=- 0xFFFFFFF ;
    s[
0 ] = 0 ;
    
for ( int  i = 1 ;i <= n; ++ i){
        cin
>> s[i];
        s[i]
+= s[i - 1 ];
        f[
0 ][i] = s[i];
    }
    
for ( int  k = 1 ;k <= m; ++ k)
        
for ( int  i = k + 1 ;i <= n; ++ i)
            
for ( int  j = i - 1 ;j >= k; -- j){
                
if (f[k][i] < f[k - 1 ][j] * (s[i] - s[j]))
                    f[k][i]
= f[k - 1 ][j] * (s[i] - s[j]);
                
if (f[k][i] < f[k - 1 ][j] + (s[i] - s[j]))
                    f[k][i]
= f[k - 1 ][j] + (s[i] - s[j]);
            }
    cout
<< f[m][n] << endl;
    
return   0 ;
}






posted on 2009-04-14 12:49 xfstart07 阅读(174) 评论(0)  编辑 收藏 引用 所属分类: 代码库

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