Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
g[
21][21], n, f[21];

void
__read__()
{
    cin 
>> n;
    
if( n == 0 )
    {
        cout 
<< 0 << endl;
        exit( 
0 );
    }
    
forint i = 1; i <= n; i++ )
        
forint j = 1; j <= i; j++ )
            cin 
>> g[i][j];
}

void
__init__()
{
    
forint i = 1; i <= n; i++ )
        f[i] 
= 2123456789;
}

inline
int
_abs( 
int x )
{
    
if( x > 0 )
        
return x;
    
return -x;
}

void
__dfs__( 
int x, int y, int sum )
{
    
if( x < n )
    {
        __dfs__( x 
+ 1, y, sum + g[x][y] );
        __dfs__( x 
+ 1, y + 1, sum + g[x][y] );
    }
    
if( x == n )
        
if( _abs( sum + g[x][y] ) < _abs( f[y] ) )
            f[y] 
= sum + g[x][y];
}

void
__outp__()
{
    
int min = 2123456789;
    
forint i = 1; i <= n; i++ )
        
if( min > _abs( f[i] ) )
            min 
= _abs( f[i] );
    cout 
<< min << endl;
}

int
main()
{
    __read__();
    __init__();
    __dfs__( 
110 );
    __outp__();

    
return 0;
}

posted on 2009-09-15 21:14 mad4alcohol 阅读(33) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理