6 5 1 4 1 6 1 7 2 7 2 8 3 0
4
We have carefully selected several similar problems for you: 1087 1159 1069 1058 1203
回归方程: f [ t ] [ x ] = max ( f [ t - 1 ] [ x - 1 ] , f [ t - 1 ] [ x ] , f [ t- 1 ] [ x + 1 ] ) + a [ t ] [ x ] ;(0<x<10)
f [ t ] [ 0 ] = max ( f [ t - 1 ] [ 0 ] , f [ t- 1 ] [ 1 ] ) + a [ t ] [ x ] ;
f [ t ] [ 10 ] = max ( f [ t - 1 ] [ 9 ] , f [ t - 1 ] [ 10 ] ) + a [ t ] [ x ] ;
#include<stdio.h> #include<string.h> #include<iostream> using namespace std; int maxi(int a,int b,int c){ int max1; max1=a>b?a:b; max1=max1>c?max1:c; return max1; } int a[100005][11]; int main(){ int n,m,i,j,x,t; while(~scanf("%d",&n)&&n){ m=0; memset(a,0,sizeof(a)); for(i=0;i<n;i++){ scanf("%d%d",&x,&t); a[t][x]++; if(m<t) m=t;; } for(i=m-1;i>=0;i--){ for(j=1;j<=9;j++) a[i][j]+=maxi(a[i+1][j-1],a[i+1][j],a[i+1][j+1]); a[i][0]+=max(a[i+1][0],a[i+1][1]); a[i][10]+=max(a[i+1][10],a[i+1][9]);//坐标为0和10的时候只有两种 } printf("%d\n",a[0][5]); } return 0; }