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 zsl2007 at 2006-01-10 17:38:15 on Problem 1163
#include<stdio.h>
#define maxlong 102 
int dp[maxlong][maxlong];
int num[maxlong];
int n,max;
int main()
{  int i,j,k,a1; 
	scanf("%d",&n);
	scanf("%d",&a1);
	dp[1][maxlong-1]=a1;
	for(i=1;i<=n-1;i++)
	 {   k=0;
	   for(j=0;j<=i;j++)
	     scanf("%d",&num[j]); 
	   
	    for(j=0;j<maxlong;j++)
	     {
		     if(dp[i][j]>0)
		      {
		       if(dp[i+1][j-1]<dp[i][j]+num[k])
		           dp[i+1][j-1]=dp[i][j]+num[k];
		        if(dp[i+1][j]<dp[i][j]+num[k+1])
		           dp[i+1][j]=dp[i][j]+num[k+1]; 
		          k++;   
		      }
		  } 
	}
	  max=0;
	for(i=0;i<maxlong;i++)	 
	  if(dp[n][i]>max)
	    max=dp[n][i];	 
	    
	  printf("%d\n",max);  	  
	}

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