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 StepByStepCnmLife at 2015-05-12 13:33:01 on Problem 1163
#include <stdio.h>
#define MAXSIZE 101
#define max(a,b) (a)>(b)?(a):(b)
int arr[MAXSIZE][MAXSIZE];
int dp[MAXSIZE][MAXSIZE]={0};
int n;
int main()
{
    int i,j,sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    for(j=0;j<=i;j++)
    {
        scanf("%d",&arr[i][j]);
    }
    for(i=n-1;i>=0;i--)
      for(j=0;j<=i;j++)
        dp[i][j]=max(dp[i+1][j]+arr[i][j],dp[i+1][j+1]+arr[i][j]);

    sum=dp[0][0];
    printf("%d\n",sum);
    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