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

Re:怎末总超时

Posted by oneman at 2011-03-30 21:45:31 on Problem 1651
In Reply To:怎末总超时 Posted by:songhaiyang at 2010-01-31 14:34:42
> #include<stdio.h>
> int c[200],n;
> void main()
> {
> 	int dp(int a,int b);
> 	int i;
> 	scanf("%d",&n);
> 	for(i=0;i<n;i++)
> 		scanf("%d",&c[i]);
> 	printf("%d\n",dp(0,n-1));
> }
> int dp(int a,int b)
> {
> 	int i,min=1000001;
> 	if(b-a<=1)
> 		return 0;
> 	else if(b-a==2)
> 		return (c[a]*c[a+1]*c[b]);
> 	else 
> 	{
> 		for(i=a+1;i<b;i++)
> 		{
> 			if(min>dp(a,i)+dp(i,b)+c[a]*c[i]*c[b])
> 				min=dp(a,i)+dp(i,b)+c[a]*c[i]*c[b];
> 		}
> 		return min;
> 	}
> }
> 	

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