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

DP,贴代码飘过~~~

Posted by yingxiang720 at 2011-03-26 19:41:02 on Problem 3176
#include <iostream>
using namespace std;

int map[351][351];
int dp[351][351];

int cmax(int a,int b)   {return a > b ? a : b;}

int main()
{
    int n,i,j,k;
    while(scanf("%d",&n)!=EOF)
    {
        for(i = 0,k = 1;i < n;i ++,k++)
            for(j = 0;j < k;j++)
                scanf("%d",&map[i][j]);
        memset(dp,0,sizeof(dp));
        for(i = n - 1;i >= 0;i--)
            for(j = 0;j <= i;j++)
                dp[i][j] = cmax(dp[i + 1][j],dp[i + 1][j + 1]) + map[i][j];
        printf("%d\n",dp[0][0]);
    }
    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