###### 动态规划—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 ;
}

#### POJ 题目3624 Charm Bracelet（动态规划 01背包）

2014-08-01 16:04:02

#### 动态规划——problem g

2016-05-21 22:16:07

#### OJ-3134 动态规划基础题目之数字三角形

2017-05-07 16:44:33

#### 动态规划Hamming_Problem 解题报告

2012年03月09日 14KB 下载

#### 找零钱问题_Change-making_Problem

2013-09-11 12:10:24

#### 动态规划之分区问题（Partition problem）

2016-10-24 18:12:39

#### 动态规划方法解旅行商问题（TSP Traveling Salesperson Problem）

2016-03-18 08:27:17

#### 动态规划之01背包问题（Knapsacks Problem）

2014-04-30 18:09:02

#### 【动态规划法】解析经典算法题Two eggs problem及其延伸问题

2017-03-28 12:04:14

#### TopCoder：ZigZag（动态规划--最长非降子序列）

2017-05-09 17:41:56