# 动态规划—Problem G

①　pie[i - 1][j - 1]
②　pie[i - 1][j]
③　pie[i - 1][j + 1]

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

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

AC代码

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std ;
int a [ 100001 ] [ 12 ] ;
int f [ 100001 ] [ 12 ] ;
int main ( )
{
int n ;
while ( cin>>n,n )
{
memset ( a, 0 , sizeof ( a ) ) ;
memset ( f, 0 , sizeof ( f ) ) ;
int x, T, i, j, maxT = 0 , ans = 0 ;
while ( n -- )
{
scanf ( "%d%d" , & x, & T ) ;
++ a [ T ] [ x ] ;
maxT = max ( maxT, T ) ;
}
f [1] [4] = a [1] [4] ;
f [1] [5] = a [1] [5] ;
f [1] [6] = a [1] [6] ;
for ( i = 2 ; i <= maxT ; ++ i )
{
for ( j = 0 ; j < 11 ; ++ j )
{
f [i] [j] = f [i-1] [j] ;
if ( j > 0 )
f [i] [j] = max ( f[i] [j] , f [i-1] [j-1] ) ;
if ( j < 10 )
f [i] [j] = max ( f [i] [j] , f [i-1] [j+1] ) ;
f [i][j] += a [i] [j] ;
}
}
for ( i = 0 ; i < 11 ; ++ i )
ans = max ( ans, f [maxT] [i] ) ;
cout<<ans<<endl;
}
return 0 ;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：动态规划—Problem G 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)