#include <iostream> #include <fstream> #include <string> using namespace std; ifstream fin("input.txt"); ofstream fout("output.txt"); int chky[8]={2,3,3,2,-2,-3,-3,-2}; int chkx[8]={3,2,-2,-3,-3,-2,2,3}; int chkt[8][8]={0}; int cnt=0,row,col; void janggi(int p,int k){ if(p>=row){ cnt++; } else{ for(int i=0;i<col;i++){ int flag=1; if(chkt[p][i]) flag=0; if(flag){ for(int j=0;j<8;j++){ if(p+chkx[j]>=0 && p+chkx[j]< row && i+chky[j]>=0 && i+chky[j]< col) if(chkt[p+chkx[j]][i+chky[j]]==0) chkt[p+chkx[j]][i+chky[j]]=p+1; } janggi(p+1,i); for(j=0;j<8;j++){ if(p+chkx[j]>=0 && p+chkx[j]< row && i+chky[j]>=0 && i+chky[j]< col) if(chkt[p+chkx[j]][i+chky[j]]==p+1) chkt[p+chkx[j]][i+chky[j]]=0; } } } } } void main(){ fin >> row >> col; janggi(0,0); fout << cnt; }
장기판에 상놓기 - 가지수
2009. 7. 29. 21:07