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 chenjin_zero at 2009-04-23 21:53:50 on Problem 1191
#include "iostream"
#include <math.h>
using namespace std;

#define N 8
#define T 15
#define MAX INT_MAX

int M;
int Map[N+1][N+1];
int sum[N+1][N+1];
int f[T][N][N][N][N];
double result;

void initF();
void dp();
int calurate(int x1,int y1,int x2,int y2);
int getMin(int a,int b);

int main()
{
	//freopen("test.txt","r",stdin);
	
	while(cin>>M)
	{
		memset(sum,0,sizeof(sum));
		for(int i=1;i<=N;i++)
		{
			for(int j=1;j<=N;j++)
			{
				cin>>Map[i][j];
				sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+Map[i][j];
			}
		}

		initF();
		dp();
	}

	return 0;
}

void initF()
{
	memset(f,0,sizeof(f));
	int i,j,k,l;
	for(i=1;i<=N;i++)
	{
		for(j=1;j<=N;j++)
		{
			for(k=1;k<=N;k++)
			{
				for(l=1;l<=N;l++)
				{
					f[0][i][j][k][l]=calurate(i,j,k,l);
				}
			}
		}
	}
}

int calurate(int x1,int y1,int x2,int y2)
{
	int a=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
	return a*a;
}

void dp()
{
	int t;
	int i,j,k,l;
	int s;
	int temp;

	for(t=1;t<M;t++)
	{
		for(i=1;i<=N;i++)
		{
			for(j=1;j<=N;j++)
			{
				for(k=1;k<=N;k++)
				{
					for(l=1;l<=N;l++)
					{
						f[t][i][j][k][l]=MAX;
						for(s=i;s<k;s++)
						{
							temp=getMin(f[t-1][i][j][s][l]+calurate(s+1,j,k,l),f[t-1][s+1][j][k][l]+calurate(i,j,s,l));
							if(temp<f[t][i][j][k][l])
								f[t][i][j][k][l]=temp;
						}
						for(s=j;s<l;s++)
						{
							temp=getMin(f[t-1][i][j][k][s]+calurate(i,s+1,k,l),f[t-1][i][s+1][k][l]+calurate(i,j,k,s));
							if(temp<f[t][i][j][k][l])
								f[t][i][j][k][l]=temp;
						}
					}
				}
			}
		}
	}

	result=sqrt(f[M-1][1][1][N][N]/(M*1.0)-sum[N][N]*sum[N][N]/(M*M*1.0));
	printf("%.3lf\n",result);
}

int getMin(int a,int b)
{
	return a<b?a:b;
}

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