#include <iostream>
using namespace std;
int getvalue(int x,int y,int step,int***q);
int process(int x,int y,int step);
int f(int x,int y,int step)
{
return process(x,y,step);
}
int process(int x,int y,int step)
{
if(x<0||x>10||y<0||y>9)
{
return 0;
}
if(step==0)
{
return (x==0&&y==0)?1:0;
}
return process(x+2,y+1,step-1)
+process(x+2,y-1,step-1)
+process(x+1,y-2,step-1)
+process(x-1,y-2,step-1)
+process(x-2,y-1,step-1)
+process(x-2,y+1,step-1)
+process(x-1,y+2,step-1)
+process(x+1,y+2,step-1);
}
int process2(int x,int y,int step)
{
if(x<0||x>10||y<0||y>9||step<0)
{
return 0;
}
int ***q=new int**[step];
for(int i = 0;i <step;i++) {
q[i]=new int*[9];
}
for(int i = 0;i < step;i++) {
for(int j = 0;j < 9;j++) {
q[i][j]=new int[10];
}
}
q[0][0][0]=1;
for(int i=0;i<step;i++)
{
for(int j=0;j<9;j++){
for(int c =0;c<10;c++)
{
cout<<getvalue(j+2,c+1,i-1,q);
q[i][j][c]+= getvalue(j+2,c+1,i-1,q);
q[i][j][c]+=getvalue(j+2,c-1,i-1,q);
q[i][j][c]+=getvalue(j+1,c-2,i-1,q);
q[i][j][c]+=getvalue(j-1,c-2,i-1,q);
q[i][j][c]+=getvalue(j-2,c-1,i-1,q);
q[i][j][c]+=getvalue(j-2,c+1,i-1,q);
q[i][j][c]+=getvalue(j-1,c+2,i-1,q);
q[i][j][c]+=getvalue(j+1,c+2,i-1,q);
}
}
}
int num=q[step][x][y];
for(int i = 0;i < step;i++) {
for(int j = 0;j < 9;j++) {
delete[] q[i][j];
}
}
for(int i = 0;i < step;i++) {
delete[] q[i];
}
delete[] q;
return num;
}
int getvalue(int x,int y,int step,int***q)
{
if(x<0||x>10||y<0||y>9||step<0)
{
return 0;
}
return q[step][x][y];
}
int main(int argc, char** argv){
cout<<process2(1,2,1);
return 0;
}
完整的题目是什么,没有题无法判断你的代码是什么问题。
是结果错误,还是啥也没输出,程序死循环?
你要输出结果,好歹得有个printf吧,写哪了