洛谷1002深搜dfs
本文最后更新于 1830 天前,其中的信息可能已经有所发展或是发生改变。

// 洛谷1002深搜dfs.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;
#define N 25
int s[N][N];
int x1, x2, h1, h2;
long sum = 0;
void creat(int h1,int h2)
{
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if ((i == (h1 - 2) && j == (h2 - 1))
				|| (i == (h1 - 2) && j == (h2 + 1))
				|| (i == (h1 - 1) && j == (h2 - 2))
				|| (i == (h1 - 1) && j == (h2 + 2))
				|| (i == (h1 + 1) && j == (h2 - 2))
				|| (i == (h1 + 1) && j == (h2 + 2))
				|| (i == (h1 + 2) && j == (h2 - 1))
				|| (i == (h1 + 2) && j == (h2 + 1))
				|| (i == h1 && j == h2 )
				)
				s[i][j] = 1;
			else
				s[i][j] = 0;
		}
	}
	
}

void dsf(int i, int j)
{
	if (i == x1&&j == x2)
	{
		sum++;
		cout << sum << endl;
		return;
	}
		
	if (i >= 0&&i<=x1&&j>=0&&j<=x2&&s[i][j]==0)
	{
		dsf(i + 1,j);
		dsf(i, j + 1);
	}

	else
		return;
}
int main()
{	
	cin >> x1 >> x2 >> h1 >> h2;
	creat(h1, h2);
	
	dsf(0, 0);
	cout << sum;
	return 0;
}

作者:Yuyy
博客:https://yuyy.info
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇