Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

自底向上

Posted by lyz963254 at 2014-08-20 21:43:00 on Problem 1163
#include <iostream>
#include <cstdio>

using namespace std;

const int M = 1005;

int i,j,k;

int Max(int x ,int y)
{
 return x>y?x:y;
}

int a[105][105];

int m[105][105];

int main ()
{
   int n;
   while (scanf ("%d",&n)!=EOF)
   {
       for (i=1;i<=n;i++)
       {
           for (j=1;j<=i;j++)
           {
               cin >> a[i][j];
           }
       }

       for (i=n;i>=1;i--)
       {
           for (j=1;j<=i;j++)
           {
               m[i][j] = Max(m[i+1][j],m[i+1][j+1]) + a[i][j]; //自底向上选择DP方向。
           }
       }

       cout <<m[1][1] <<endl;

   }

return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator