题目:http://poj.org/problem?id=3176  

bowl[i][j] += max( bowl[i-1][j-1], bowl[i-1][j]);

 

代码:

#include <stdio.h>
#include <string.h>

int bowl[355][355];

int main()
{
   int row,i,j,tmp; 
   
     while(~scanf("%d",&row))
     {
         for(i = 0 ; i < row ; ++i)
         for(j = 0 ; j <= i ; ++j)
         scanf("%d",&bowl[i][j]);                        
                     
         for(i = 1 ; i < row ; ++i)             
         {
               bowl[i][0] += bowl[i-1][0];
               bowl[i][i] += bowl[i-1][i-1];
         }
         
         for(i = 2 ; i < row ; ++i)
         for(j = 1 ; j < i ; ++j)
         {
            tmp = bowl[i-1][j-1] > bowl[i-1][j] ? bowl[i-1][j-1]: bowl[i-1][j];
            bowl[i][j] += tmp;      
         }
         tmp = -1;       
         for(i = 0 ; i < row ; ++i)
         if(bowl[row-1][i] > tmp)
         tmp = bowl[row-1][i];
         
         printf("%d\n",tmp);       
     } 
   //system("pause");  
   return 0;   
} 

 


           

相关文章:

  • 2021-11-16
  • 2022-12-23
  • 2021-10-19
  • 2021-07-28
  • 2021-05-22
  • 2021-12-13
  • 2022-02-17
猜你喜欢
  • 2021-09-02
  • 2022-03-07
  • 2021-07-22
  • 2022-12-23
  • 2021-11-20
  • 2022-02-16
相关资源
相似解决方案