比赛 202103省实验桐柏一中普及组联赛 评测结果 AAAAAAAAAA
题目名称 亡羊补牢,未为迟也 最终得分 100
用户昵称 tb_PYD1 运行时间 0.081 s
代码语言 C++ 内存使用 0.59 MiB
提交时间 2021-03-22 18:06:27
显示代码纯文本
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

inline int read(){
	int t = 0,flag = 1;
	register char c = getchar();
	while (c < 48 || c > 57) flag = (c == '-') ? (-1) : (flag),c = getchar();
	while (c >= 48 && c <= 57) t = (t << 1) + (t << 3) + (c ^ 48),c = getchar();
	return flag * t;
}

int n,m,ans[30],dx[9] = {-2,-1,1,2,2,1,-1,-2,0},dy[9] = {-1,-2,-2,-1,1,2,2,1,0};
bool mp[21][21];

void check(){
	int sum = 0;
	for (int i = 1;i <= n;i++){
		for (int j = 1;j <= m;j++){
			if (mp[i][j]) ++sum;
			bool flag = 0;
			for (int k = 0;k <= 8;k++){
				int xx = i + dx[k],yy = j + dy[k];
				if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
				if (mp[xx][yy]){
					flag = 1;
					break;
				}
			}
			if (!flag) return ;
		}
	}
	++ans[sum];
}

void dfs(int i,int j){
	if (i == n + 1){
		check();
		return ;
	}
	if (j == m) dfs(i + 1,1),mp[i][j] = 1,dfs(i + 1,1),mp[i][j] = 0;
	else dfs(i,j + 1),mp[i][j] = 1,dfs(i,j + 1),mp[i][j] = 0;
}

int main(){
	freopen("secretnum.in","r",stdin);
	freopen("secretnum.out","w",stdout);
	n = read(),m = read();
	dfs(1,1);
	for (int i = 0;i <= n * m;i++){
		if (ans[i]){
			printf("%d %d\n",i,ans[i]);
			return 0;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}