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思想 为什么wrong了

Posted by nenu_cs_11yanyao at 2012-07-19 21:04:04 on Problem 1157
除了第一排
下面每1个花是前一排的dp的最大值。。到最后再求最后一排的最大值为什么错了
dp[i][j]=dp[i-1][j-1]+map[i][j];
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define M 108
int map[M][M];
int dp[M][M];
int max(int x,int y)
{
	if(x>y)
		return x;
	else
		return y;
}
int main()
{
	int i,j,k,r,c,t1;
	while(~scanf("%d%d",&r,&c))
	{
		for(i=1;i<=r;i++)
			for(j=1;j<=c;j++)
			{
				scanf("%d",&map[i][j]);
			}
		for(i=1;i<=r;i++)
			for(j=1,t1=-100000;j<=c;j++)
			{
				dp[i][j]=-1000000;
			}
		for(i=1;i<=r;i++)
			for(j=i,t1=-100000;j<=c;j++)
			{
				if(i==1)
				{
					dp[i][j]=max(t1,map[i][j]);
					t1=dp[i][j];
				}
				else
				{
					dp[i][j]=(map[i][j]+dp[i-1][j-1]);
				}
			}
	/*	for(i=1;i<=r;i++)
		{
			for(j=1;j<=c;j++)
			{
				printf("%9d ",dp[i][j]);
			}
			printf("\n");
		}*/
		for(i=1,t1=-10000000;i<=c;i++)
		{
			if(dp[r][i]>t1)
			{
				t1=dp[r][i];
			}
		}
		printf("%d\n",t1);
	//	printf("%d\n",dp[r][c]);

	}
	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