Metal Steak

Hard to eat

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

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int
g[
11][11], n, ans[11][11], answ = 0;

void
__read__()
{
    
int x, y, w;
    cin 
>> n;
    
while( cin >> x >> y >> w )
        
if( x > 0 )
            g[x][y] 
= w;
        
else
            
break;
}

int
__dp__()
{
    memset( ans, 
0sizeof ans );
    
forint i = 1; i <= n; i++ )
        
forint j = 1; j <= n; j++ )
            
if( ans[i - 1][j] > ans[i][j - 1] )
                ans[i][j] 
= ans[i - 1][j] + g[i][j];
            
else
                ans[i][j] 
= ans[i][j - 1+ g[i][j];

    
return ans[n][n];
}

void
__dfs__( 
int x, int y, int sum )
{
    
if( x == n && y == n )
    {
        
int t = __dp__();
        
if( t + sum > answ )
            answ 
= t + sum;
    }
    
if( x <= n && y <= n )
    {
        
int tmp = g[x][y];
        g[x][y] 
= 0;
        __dfs__( x, y 
+ 1, sum + tmp );
        __dfs__( x 
+ 1, y, sum + tmp );
        g[x][y] 
= tmp;
    }
}

void
__outp__()
{
    cout 
<< answ << endl;
}

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

    
return 0;
}

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

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