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 DMChusen at 2012-09-01 20:41:25 on Problem 2948
In Reply To:40行代码解决,偶也~发现记忆化搜索比正向递推好用~ Posted by:yzhw at 2010-08-17 18:00:14
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int size=510;
int n,m;
int g[2][size][size],f[2][size][size],s[2][size][size];
int main()
{
	int i,j,k;
	while(scanf("%d%d",&n,&m)==2)
	{
		if(!n&&!m)
			break;
		memset(f,0,sizeof(f));
		memset(s,0,sizeof(s));	
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
			{	
				scanf("%d",&g[0][i][j]);
				s[0][i][j]=s[0][i][j-1]+g[0][i][j];
			}
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
			{
				scanf("%d",&g[1][i][j]);				
				s[1][i][j]=s[1][i-1][j]+g[1][i][j];
			}
		for(i=1;i<=n;i++)
			for(j=1;j<=m;j++)
			{
				f[0][i][j]=max(f[0][i-1][j],f[1][i-1][j])+s[0][i][j];
				f[1][i][j]=max(f[0][i][j-1],f[1][i][j-1])+s[1][i][j];
			}
		int ans=max(f[0][n][m],f[1][n][m]);
		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