UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#211938#3815. 种树zhangry1001ms1264kbC++1.1kb2024-10-13 08:58:082024-10-13 12:51:53

answer

#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define awa return 0;
using namespace std;
int n,m;
int k;
int ans;
vector<vector<int> > a;
bool check(int x,int y)
{
    if(a[x][y]==1)
    {
        return false;
    }
    if(x>0&&a[x-1][y]==1)
    {
        return false;
    }
    if(x<n-1&&a[x+1][y]==1)
    {
        return false;
    }
    if(y>0&&a[x][y-1]==1)
    {
        return false;
    }
    if(y<m-1&&a[x][y+1]==1)
    {
        return false;
    }
    return true;
}
void tree(int p,int x,int y)
{
    if(p==k)
    {
        ans++;
        return ;
    }
    for(int i=x;i<n;i++)
    {
        for(int j=(i==x?y:0);j<m;j++)
        {
            if(check(i,j))
            {
                a[i][j]=1;
                tree(p+1,i,j+1);
                a[i][j]=0;
            }
        }
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    cin>>k;
    a=vector<vector<int> >(n,vector<int>(m,0));
    tree(0,0,0);
    cout<<ans;
    awa
}
//

详细

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

Test #1:

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

input:

2 2 1

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

2 3 2

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

4 4 2

output:

96

result:

ok 1 number(s): "96"

Test #4:

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

input:

4 4 5

output:

304

result:

ok 1 number(s): "304"

Test #5:

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

input:

3 4 3

output:

84

result:

ok 1 number(s): "84"

Test #6:

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

input:

3 5 2

output:

83

result:

ok 1 number(s): "83"

Test #7:

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

input:

3 5 3

output:

215

result:

ok 1 number(s): "215"

Test #8:

score: 10
Accepted
time: 1ms
memory: 1264kb

input:

3 5 4

output:

276

result:

ok 1 number(s): "276"

Test #9:

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

input:

3 5 5

output:

174

result:

ok 1 number(s): "174"

Test #10:

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

input:

4 3 5

output:

18

result:

ok 1 number(s): "18"

Extra Test:

score: 0
Extra Test Passed