题目:U461288 国王放置
#include <bits/stdc++.h>
using namespace std;
int n,m,k,ans;
int _hash[5][5];
void work(int x,int y,int tot){
int i,j;
if (tot==k){
ans++;
return;
}
do{
while (_hash[x][y]){
y++;
if (y==m){
x++;
y=0;
}
if (x==n)
return;
}
for (i=x-1;i<=x+1;i++)
if (i>=0&&i<n)
for (j=y-1;j<=y+1;j++)
if (j>=0&&j<m)
_hash[i][j]++;
work(x,y,tot+1);
for (i=x-1;i<=x+1;i++)
if (i>=0&&i<n)
for (j=y-1;j<=y+1;j++)
if (j>=0&&j<m)
_hash[i][j]--;
y++;
if (y==m){
x++;
y=0;
}
if (x==n)
return;
}while (1);
}
int main(){
cin >> n >> m >> k;
ans=0;
memset(_hash,0,sizeof(_hash));
work(0,0,0);
cout << ans << endl;
return 0;
}