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 lankd at 2007-10-01 13:39:33 on Problem 3186
#include <stdio.h>
#include <string.h>

#define MAX_LEN 2005
int array[MAX_LEN] = {0};
int OutputResult(int array[], int low, int high, int i );
int MinValue(int a, int b);

int main()
{
    int input = 0;
	int i = 0;
	int  maxProfile = 0;
    

	scanf("%d", &input);
	for( i = 0; i < input; i++ )
	{
		scanf("%d", &array[i]);
	}
    
	maxProfile = OutputResult( array, 0, input - 1, 1);
	printf("%d\n", maxProfile);
	return 0; 
}

int OutputResult( int array[], int low, int high, int i)
{   
    int minValue = 0;
    int static totleValue = 0;

	if(low == high)
	{
		totleValue += i * array[low];
		return totleValue;
	}

	minValue = MinValue(array[low], array[high]);

	if( minValue == array[low] )
	{
       totleValue = i*array[low] + OutputResult(array, low + 1, high, i+1);
	}
	else
	{
		totleValue = i*array[high] + OutputResult(array, low, high - 1, i+1);
	}
	return totleValue;
}

int MinValue(int  a, int  b)
{
	return (a > b)? b : a;
}

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