Uva10285最长的滑雪记录

这真的是一道动态规划题吗?感觉时间复杂度很高·····

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 10005
//
 
int Map[105][105];
int count1[MAX];
int R, C;

int dx[] = { 0,-1,0,1 };
int dy[] = { 1,0,-1,0 };

int DP(int r, int c)
{//if(count1[r*C+c]>=1)return c

	for (int i = 0; i < 4; i++)
	{
		int tr = r + dx[i];
		int tc = c + dy[i];
		if (tr >= R || tr < 0 || tc >= C || tc < 0)continue;
		if (Map[tr][tc] < Map[r][c])
		{
			count1[r * C + c] = max(DP(tr, tc) + 1, count1[r * C + c]);
		}
	}
	return count1[r * C + c];
}

int main()
{
	freopen("sb.txt", "r", stdin);
	ios::sync_with_stdio(false);
	int casenum;

	cin >> casenum;
	while (casenum--)
	{
		memset(Map, 0, sizeof(Map));
		string name;
		fill(count1, count1 + MAX, 1);
		cin >> name;
		cin >> R >> C;
		for(int i=0;i<R;i++)
			for (int j = 0; j < C; j++)
			{
				cin >> Map[i][j];
				
			}
		int ans = -0x3f3f3f3f;
		for(int i=0;i<R;i++)
			for (int j = 0; j < C; j++)
			{
				ans = max(ans, DP(i, j));
		//		cout << ans<< endl;
			}
		cout << name + ": " << ans << endl;
	}

	return 0;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值