3 solutions

  • 0
    @ 2022-2-16 13:12:04
    #include<bits/stdc++.h>
    using namespace std;
    int n,m,cnt=1;
    int a[2][10];
    void dfs(int x,int y,int len,int a[][10]){
    	a[0][len]=x;
    	a[1][len]=y;
    	if(x>n||y>m||x<0||y<0)
    	return;
    	else if(x==n&&y==m){
    		cout<<cnt<<":";
    		cnt++;
    		for(int i=0;i<=len;i++){
    			if(i==len)
    			printf("%d,%d\n",a[0][i],a[1][i]);
    			else
    			printf("%d,%d->",a[0][i],a[1][i]);
    		}
    		return;
    	}
    	dfs(x+2,y+1,len+1,a);
    	dfs(x+1,y+2,len+1,a);
    	dfs(x-1,y+2,len+1,a);
    	dfs(x-2,y+1,len+1,a);
    }
    int main()
    {
    	//cin>>n>>m;
    	n=4,m=8;
    	dfs(0,0,0,a);
    	return 0;
    }
    

    Information

    ID
    699
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    5
    Tags
    # Submissions
    96
    Accepted
    36
    Uploaded By