Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Matrix paths right-down only, going through XY
#include <iostream> void printAllPathsXY(int *mat, int i, int j, int m, int n, int *path, int pi,bool q,int x, int y) { if (i==x & j==y) { q=true; } if (i == m - 1) { for (int k = j; k < n; k++) { path[pi + k - j] = *(mat + (m-1)*n + k); if (i==x & k==y) { q=true; } } if (q) { for (int l = 0; l < pi + n - j; l++) std::cout << path[l] << " "; std::cout << "\n"; } q=false; return; } if (j == n - 1) { for (int k = i; k < m; k++) { path[pi + k - i] = *(mat + k*n + n-1); if (k==x & j==y) { q=true; } } if(q) { for (int l = 0; l < pi + m - i; l++) std::cout << path[l] << " "; std::cout << "\n"; } q=false; return; } path[pi] = *(mat + i*n + j); printAllPathsXY(mat, i+1, j, m, n, path, pi + 1,q,x,y); printAllPathsXY(mat, i, j+1, m, n, path, pi + 1,q,x,y); } void printA(int *mat, int m, int n, int x, int y) { int *path = new int[m+n]; printAllPathsXY(mat, 0, 0, m, n, path, 0,false,x,y); } int main() { int x=2; int y=2; int mat[3][3] = { {1, 4, 7}, {2, 5, 8},{3, 6, 9} }; printA(*mat, 3, 3,x,y); }
run
|
edit
|
history
|
help
0
Structured Member Value Access Using Structure Member Pointer and Variadic Templates
Integral constant
#21.2
delete from list
#22.2
Two-phase sample with VC++ 2015
sharedptr emptiness
-1 Girene Kadar Ortalama
cv4_template
upper_bound With binary_function Visual Studio 2008 Bug?