免费馅饼

http://acm.hdu.edu.cn/showproblem.php?pid=1176

#include 
#include
//#include
using namespace std;
int MaxOf2(int a, int b){
    return (a > b) ? a : b;
}

int MaxOf3(int a, int b, int c){
    int m = (a > b) ? a : b;
    return (m > c) ? m : c;
}
int dp[11][100010];
int main()
{

  int n;

  while(~scanf("%d",&n),n)
  {
      int a,b;
      int mt=-1;
      memset(dp,0,sizeof(dp));
      for(int i=0;imt) mt=b;
      }
         for(int j=mt-1;j>=0;j--)
         {
             for(int k=1;k<=9;k++ )
             {
                 dp[k][j]+=MaxOf3(dp[k-1][j+1],dp[k][j+1],dp[k+1][j+1]);
             }
             dp[0][j]+=MaxOf2(dp[0][j+1],dp[1][j+1]);
             dp[10][j]+=MaxOf2(dp[10][j+1],dp[9][j+1]);
         }
     printf("%d\n",dp[5][0] );
  }

  return 0;
}

你可能感兴趣的:(免费馅饼)