60分蒟蒻,3,4评测WA
查看原帖
60分蒟蒻,3,4评测WA
528460
12tianxun楼主2021/8/30 14:29

不知道为什么,
3,4题怎么改都不对
使用算法动态规划

#include<iostream>
using namespace std;
int main()
{
	long long B[21][21];
	int n,m,horsex,horsey;
	cin>>n>>m>>horsex>>horsey;
	for(int i = 0; i<=n; i++){
		for(int j = 0 ; j<=m ;j++){
			B[i][j] = 1;
		}
	}
	B[horsex][horsey] = 0;
	B[horsex+2][horsey+1] = 0;
	if(horsex-2>0)
	{
		B[horsex-2][horsey+1] = 0;
		B[horsex-1][horsey+2] = 0;
	}
	if(horsey-2>0)
	{
		B[horsex+2][horsey-1] = 0;
		B[horsex+1][horsey-2] = 0;
	}
	B[horsex+1][horsey+2] = 0;
	if(horsey-2>0&&horsex-2>0)
	{
		B[horsex-2][horsey-1] = 0;
		B[horsex-1][horsey-2] = 0;
	}
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			if(B[i][j]!=0)
			{
				if(i == 0||j == 0) 
					B[i][j] = 1;
				else 
					B[i][j] = B[i-1][j] + B[i][j-1];
			}		
		}
	}
	cout<<B[n][m];
	return 0; 
}
2021/8/30 14:29
加载中...