50分求改
  • 板块题目总版
  • 楼主Moco_jof
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/8/11 17:54
  • 上次更新2024/8/11 19:44:31
查看原帖
50分求改
1204055
Moco_jof楼主2024/8/11 17:54

题目:U461288 国王放置

#include <bits/stdc++.h>
using namespace std;

int n,m,k,ans;
int _hash[5][5];
void work(int x,int y,int tot){
	int i,j;
	if (tot==k){
		ans++;
		return;
	}
	do{
		while (_hash[x][y]){
			y++;
			if (y==m){
				x++;
				y=0;
			}
			if (x==n)
				return;
		}
		for (i=x-1;i<=x+1;i++)
			if (i>=0&&i<n)
				for (j=y-1;j<=y+1;j++)
					if (j>=0&&j<m)
					   _hash[i][j]++;
		work(x,y,tot+1);
		for (i=x-1;i<=x+1;i++)
			if (i>=0&&i<n)
				for (j=y-1;j<=y+1;j++)
					if (j>=0&&j<m)
					    _hash[i][j]--;
		y++;
		if (y==m){
			x++;
			y=0;
		}
		if (x==n)
			return;
	}while (1);

}
int main(){
	cin >> n >> m >> k;
	ans=0;
	memset(_hash,0,sizeof(_hash));
	work(0,0,0);
	cout << ans << endl;
	return 0;
}

2024/8/11 17:54
加载中...