UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212173#3815. 种树chendongyu1000ms1188kbC++111.1kb2024-10-13 11:49:122024-10-13 12:56:21

answer

#include<bits/stdc++.h>
using namespace std;
long long n,m,k,ans;
long long f[26];
long long vis[20][20];
long long move_[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
long long funny(long long x,long long y,long long sum)
{
	sum--;
	vis[x][y]++;
	for(int i=0;i<4;i++)
	{
		int x1=x+move_[i][0];
		int y1=y+move_[i][1];
		if(x1&&y1&&x1<=n&&y1<=m)
		{
			if(!vis[x1][y1])
				sum--;
			vis[x1][y1]++;
		}
	}
	return sum;
}
long long sadly(long long x,long long y)
{
	vis[x][y]--;
	for(int i=0;i<4;i++)
	{
		int x1=x+move_[i][0];
		int y1=y+move_[i][1];
		if(x1&&y1&&x1<=n&&y1<=m)
			vis[x1][y1]--;
	}
}
void dfs(int t,int num)
{
	if(t==k-1)
	{
		ans+=num;
		return;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(vis[i][j]==false)
			{
				dfs(t+1,funny(i,j,num));
				sadly(i,j);
			}
		}
	}
}
int main()
{
	f[0]=1;
	for(int i=1;i<=20;i++)
		f[i]=f[i-1]*i;
	cin>>n>>m>>k;
	if(n==1||m==1)
	{
		if(2*k>n*m)
			ans=0;
		else
			ans=f[n*m-k]/f[n*m-2*k];
	}
	else
	{
		dfs(0,n*m);
	}
	printf("%lld",ans/f[k]);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

2 2 1

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

2 3 2

output:

8

result:

ok 1 number(s): "8"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

4 4 2

output:

96

result:

ok 1 number(s): "96"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

4 4 5

output:

304

result:

ok 1 number(s): "304"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

3 4 3

output:

84

result:

ok 1 number(s): "84"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

3 5 2

output:

83

result:

ok 1 number(s): "83"

Test #7:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

3 5 3

output:

215

result:

ok 1 number(s): "215"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

3 5 4

output:

276

result:

ok 1 number(s): "276"

Test #9:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

3 5 5

output:

174

result:

ok 1 number(s): "174"

Test #10:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

4 3 5

output:

18

result:

ok 1 number(s): "18"

Extra Test:

score: 0
Extra Test Passed