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

找最大值的时候..忘了把m初始。。送了2个WA。。郁闷,dp 0ms

Posted by boy_lt at 2009-09-24 17:19:15 on Problem 1163 and last updated at 2009-09-24 17:20:18
#include<iostream>
using namespace std;
int a[101][101],re[101][101];
int N;
int max(int a,int b){return a>b?a:b;}
void init()
{
	int i,j;
	memset(a,0,sizeof(a));
	memset(re,0,sizeof(re));
	for(i=1;i<=N;i++)
		for(j=1;j<=i;j++)
			scanf("%d",a[i]+j);
}
int dp()
{
	int i,j,m=0;
	for(i=1;i<=N;i++)
		for(j=1;j<=i;j++)
			re[i][j]=max(re[i-1][j],re[i-1][j-1])+a[i][j];
	for(i=1;i<=N;i++)m=max(m,re[N][i]);
	return m;
}
int main()
{
	while(scanf("%d",&N)!=EOF)
	{
    	init();
    	printf("%d\n",dp());
	}
	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