比赛 2024暑假C班集训A 评测结果 AAAAAAAAAT
题目名称 牧场的安排 最终得分 90
用户昵称 袁书杰 运行时间 2.299 s
代码语言 C++ 内存使用 3.35 MiB
提交时间 2024-07-10 10:46:03
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
long long m,n,a[15][15],ans=1,ans1,a1[15][15];
bool flag=false;
void dfs(long long x,long long y) {
	for(long long i=x; i<=m; i++) {
		for(long long j=y; j<=n; j++) {
			if(a[i][j]==1) {
				ans++;
				ans%=100000000;
				a[i][j]=0;
				if(i-1>=1) {
					a[i-1][j]--;
				}
				if(j-1>=1) {
					a[i][j-1]--;
				}
				if(i+1<=m) {
					a[i+1][j]--;
				}
				if(j+1<=n) {
					a[i][j+1]--;
				}
				dfs(i,j);
				a[i][j]=1;
				if(i-1>=1) {
					a[i-1][j]++;
				}
				if(j-1>=1) {
					a[i][j-1]++;
				}
				if(i+1<=m) {
					a[i+1][j]++;
				}
				if(j+1<=n) {
					a[i][j+1]++;
				}
			}
		}
		y=1;
	}
}
int main() {
    freopen("cowfood.in","r",stdin);
    freopen("cowfood.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>m>>n;
	for(long long i=1; i<=m; i++) {
		for(long long j=1; j<=n; j++) {
			cin>>a[i][j];
			a1[i][j]=a[i][j];
		}
	}
	for(long long i=1; i<=m; i++) {
		for(long long j=1; j<=n; j++) {
			if(a[i][j]==1) {
				ans++;
				ans%=100000000;
				a[i][j]=0;
				if(i-1>=1) {
					a[i-1][j]--;
				}
				if(j-1>=1) {
					a[i][j-1]--;
				}
				if(i+1<=m) {
					a[i+1][j]--;
				}
				if(j+1<=n) {
					a[i][j+1]--;
				}
				dfs(i,j);
				for(long long aa=1; aa<=m; aa++) {
					for(long long bb=1; bb<=n; bb++) {
						a[aa][bb]=a1[aa][bb];
					}
				}
			}
		}
	}
	ans%=100000000;
	cout<<ans;
	return 0;
}