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 huxipeng at 2013-12-31 20:58:41 on Problem 1050
#include<iostream>
using namespace std;
#define M 254
int t,m;
int n;
int num[M][M];
int submax(int a[M])
{
	int pre;
	int max=0;
    pre=a[1];
	for(int i=2;i<=n;i++)
	{
       if(a[i]+pre>a[i])
		   pre=a[i]+pre;
	   else 
	       pre=a[i];
	   if(pre>max)
		   max=pre;
	}
	return max;
}
int submax2(int a[][M])
{
    int max=0;
    int b[M];
	for(int i=1;i<=n;i++)
	{
	     memset(b,0,sizeof(b));
		 for(int j=i;j<=n;j++)
		 {
			 for(int k=1;k<=n;k++)
				 b[k]+=a[j][k];
		
			 int f=submax(b);
		     if(f>max)
			    max=f;
		 }
	}
	return max;
}

int main()
{
   
   while(cin>>n)
   {
       for( t=1;t<=n;t++)
		   for(m=1;m<=n;m++)
			   cin>>num[t][m];

	   int max=submax2(num);
	   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