4 solutions
-
0
#include<bits/stdc++.h> using namespace std; const int N=20; int n,m,a[N][N],deep=0,cnt=1; int dx[2]={1,0}; int dy[2]={0,1}; void dfs(int nx,int ny,int deep) { a[deep][1]=nx; a[deep][2]=ny; if(nxn&&nym){ cout<<cnt<<":"; cnt++; for(int i=0;i<=deep;i++){ cout<<a[i][1]<<","<<a[i][2]; if(i!=deep){ cout<<"->"; } } cout<<endl; return; } for(int i=0;i<2;i++){ int x=nx+dx[i]; int y=ny+dy[i]; if(x>=1&&x<=n&&y>=1&&y<=m){ dfs(x,y,deep+1); } } } int main() { cin>>n>>m; dfs(1,1,deep); return 0; }
Information
- ID
- 697
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- 5
- Tags
- # Submissions
- 249
- Accepted
- 88
- Uploaded By