新boj84

Android key

#include <stdio.h> #include <stdlib.h> #include <memory.h> int res=0; void check(int **score,int Max,int m,int n,int row,int col,int step) { if(step==1) score[row][col]=1; if(step==Max) { res++; return; } else { if(row-1>=0&&score[row-1][col]!=1)//up { score[row-1][col]=1; check(score,Max,m,n,row-1,col,step+1); score[row-1][col]=0; } if(row+1<m&&score[row+1][col]!=1)//down { score[row+1][col]=1; check(score,Max,m,n,row+1,col,step+1); score[row+1][col]=0; } if(col-1>=0&&score[row][col-1]!=1)//left { score[row][col-1]=1; check(score,Max,m,n,row,col-1,step+1); score[row][col-1]=0; } if(col+1<n&&score[row][col+1]!=1)//right { score[row][col+1]=1; check(score,Max,m,n,row,col+1,step+1); score[row][col+1]=0; } } } int main(int argc, char *argv[]) { int n,m,k; int i,j=0,player=0,p,q; while(scanf (“%d%d%d”,&n,&m,&k)==3) { if(k==0){printf(“0/n”);continue;} int **row=(int **)malloc(sizeof(int)*m); for(i=0;i<m;i++) { row[i]=(int *)malloc(sizeof(int)*n); for(j=0;j<n;j++) row[i][j]=0; } res=0; for(i=0;i<m;i++) { for(j=0;j<n;j++) { check(row,k,m,n,i,j,1); row[i][j]=0; } } printf(“%d/n”,res); } return 0; }

点赞