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 yingxiang720 at 2011-03-28 17:03:11 on Problem 1163
#include <iostream>
using namespace std;
int map[351][351];
int dp[351][351];
int n;
int cmax(int a,int b)   {return a > b ? a : b;}
int d(int i,int j)
{
    if(dp[i][j] >= 0)   return dp[i][j];
    return dp[i][j] = map[i][j] + (i == n - 1 ? 0 : cmax(d(i + 1,j),d(i + 1,j + 1)));
}
int main()
{
    int 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,-1,sizeof(dp));
        int ans = d(0,0);
        printf("%d\n",ans);
    }
    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