ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#211930 | #3815. 种树 | zhaonijun | 100 | 0ms | 1248kb | C++ | 814b | 2024-10-13 08:55:06 | 2024-10-13 12:51:32 |
answer
#include<bits/stdc++.h>
using namespace std;
int n,m,k,mp[20][20],dx[]={-1,1,0,0},dy[]={0,0,-1,1};
long long res=0;
bool check(int x,int y)
{
for (int i=0;i<4;i++)
{
int nwx=x+dx[i],nwy=y+dy[i];
if (x<1||x>n||y<1||y>m) continue;
if (mp[nwx][nwy]) return false;
}
return true;
}
void dfs(int x,int y,int cnt)
{
if ((x==-1&&y==-1)||cnt==k)
{
if (cnt==k) res++;
return ;
}
if (check(x,y))
{
mp[x][y]=1;
if (x==n&&y==m) dfs(-1,-1,cnt+1);
else if (y==m) dfs(x+1,1,cnt+1);
else dfs(x,y+1,cnt+1);
mp[x][y]=0;
}
if (x==n&&y==m) dfs(-1,-1,cnt);
else if (y==m) dfs(x+1,1,cnt);
else dfs(x,y+1,cnt);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>k;
memset(mp,0,sizeof(mp));
dfs(1,1,0);
cout<<res;
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
2 2 1
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 10
Accepted
time: 0ms
memory: 1240kb
input:
2 3 2
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
4 4 2
output:
96
result:
ok 1 number(s): "96"
Test #4:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
4 4 5
output:
304
result:
ok 1 number(s): "304"
Test #5:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
3 4 3
output:
84
result:
ok 1 number(s): "84"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
3 5 2
output:
83
result:
ok 1 number(s): "83"
Test #7:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
3 5 3
output:
215
result:
ok 1 number(s): "215"
Test #8:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
3 5 4
output:
276
result:
ok 1 number(s): "276"
Test #9:
score: 10
Accepted
time: 0ms
memory: 1244kb
input:
3 5 5
output:
174
result:
ok 1 number(s): "174"
Test #10:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
4 3 5
output:
18
result:
ok 1 number(s): "18"
Extra Test:
score: 0
Extra Test Passed