数塔问题-免费馅饼

#include <iostream>
using std::max;
const int MAX_NUM = 100002;
int pea[MAX_NUM][11];
void setZero ( int t )
{
     
for ( int i = 0; i <= t; ++i )
     {
          
for ( int j = 0; j != 11++ j )
          {
              pea[i][j] 
= 0;
          }
     }
}
int main ()
{
    
int N,temp = MAX_NUM;
    
while ( scanf ("%d",&N), N != 0 )
    {
          setZero ( temp );
          
int pos,sec;
          
int maxSec = 0;
          
for ( int i = 0; i != N; ++i )
          {
               scanf ( 
"%d%d",&pos,&sec ) ;
               pea[sec][pos] 
++ ;
               
if ( maxSec < sec )
               {
                    maxSec 
= sec;
               }
          } 
          temp 
= maxSec;
         
for ( int i = maxSec; i != 0  ; -- i )
         {
              
for ( int j = 0; j != 11++ j )
              {
                   
if ( j == 0 )
                   {
                        pea[i
-1][j] += max ( pea[i][0] , pea[i][1] );
                   }
                   
else if ( j == 10 ) 
                   {
                        pea[i
-1][j] += max ( pea[i][9], pea[i][10] );  
                   }
                   
else
                   {
                        pea[i
-1][j] += max ( max ( pea[i][j-1], pea[i][j] ), pea[i][j+1] );
                   }   
             }
         }    
         printf ( 
"%d\n",pea[0][5] );  
    }
    
return 0
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值