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

求助 1157

Posted by jiangshuibujie at 2012-03-09 22:16:28
#include<iostream>


using namespace std;
int max(int a,int b)
{
    if(a>b)
		return a;
	return b;

}
int main()
{
    int map[101][101];
    int cost[101][101];
    int i,j,k;
	int Max;
	int N,M;
	
	cin>>N>>M;
    for( i=1 ; i<=N ; i++ )
	{
		for( j=1 ; j<=M ; j++ )
		{
		    cin>>map[i][j];		
		}
    }
	 
    memset(cost,0,sizeof(cost));
	cost[0][0]=INT_MIN;
    Max=INT_MIN;
	for(j=1;j<=M;j++)
		cost[1][j]=max(cost[1][j-1],map[1][j]);
    for( i=2 ; i<=N ; i++ )
		for( j=i ; j<=M ; j++ )
		{
		    for( k=i-1 ; k<j;k++)
				cost[i][j]=max(cost[i-1][k]+map[i][j],cost[i][j]);
			if(i==N)
				Max=max(Max,cost[i][j]);
		
		}
	
        cout<<Max<<endl;
    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