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

个人的简单思路,分享下,代码已AC

Posted by wwfdzh2013 at 2014-01-10 22:01:13 on Problem 1088
#include<stdio.h>
#define R 101
#define C 101
int h=0;
int map[R+1][C+1];
int high[R+1][C+1];
int r,c;
int fac(int i,int j)
{
	int temp=0,max_high=0;//max_high为当前坐标的四个方向的最大降序长度
	if(i<r&&j<c&&i>-1&&j>-1)//越界判断
	{
		if(high[i+1][j]==1&&map[i+1][j]<map[i][j])//若下一方向的记忆数组的值为初始值且满足降序,则向下探索
			temp=fac(i+1,j);
		else if(map[i+1][j]<map[i][j])//否则的话如果是降序但记忆数组的值不是初始值,则说明下一方向此前已探索,将其最大长度记录给temp
			temp=high[i+1][j];
		if(temp>max_high)//替换较大的降序长度
			max_high=temp;
		if(high[i][j+1]==1&&map[i][j+1]<map[i][j])
			temp=fac(i,j+1);
		else if(map[i][j+1]<map[i][j])
			temp=high[i][j+1];
		if(temp>max_high)
			max_high=temp;
		if(high[i-1][j]==1&&map[i-1][j]<map[i][j])
			temp=fac(i-1,j);
		else if(map[i-1][j]<map[i][j])
			temp=high[i-1][j];
		if(temp>max_high)
			max_high=temp;
		if(high[i][j-1]==1&&map[i][j-1]<map[i][j])
			temp=fac(i,j-1);
		else if(map[i][j-1]<map[i][j])
			temp=high[i][j-1];
		if(temp>max_high)
			max_high=temp;
		return max_high+1;
	}
	else
		return 0;//数组越界
}
/*
思路为将大问题分割为等价小问题,即将全局最优分解为局部最优,为了避免多余的计算,设一辅助记忆数组high[][]记忆每个坐标
的最大降序长度,用递归实现
*/
int main()
{
	int i,j;
	scanf("%d%d",&r,&c);
	for(i=0;i<r;i++)
		for(j=0;j<c;j++)
			scanf("%d",&map[i][j]);
	for(i=0;i<r;i++)//辅助数组初始化
		for(j=0;j<c;j++)
			high[i][j]=1;
	for(i=0;i<r;i++)//逐一计算每个位置的最大降序长度
		for(j=0;j<c;j++)
			high[i][j]=fac(i,j);
	for(i=0;i<r;i++)
		for(j=0;j<c;j++)
			if(high[i][j]>h)
				h=high[i][j];
	printf("%d\n",h);
}

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