0% found this document useful (0 votes)
6 views22 pages

Recursive Algorithms in C++

The document contains code snippets for various algorithms, including a backtracking approach for generating combinations, validating Sudoku board conditions, and solving a configuration problem recursively. It also includes a function for counting paths in a grid while avoiding obstacles. The code demonstrates the use of recursion and condition checks to solve these problems effectively.

Uploaded by

Anime Z
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views22 pages

Recursive Algorithms in C++

The document contains code snippets for various algorithms, including a backtracking approach for generating combinations, validating Sudoku board conditions, and solving a configuration problem recursively. It also includes a function for counting paths in a grid while avoiding obstacles. The code demonstrates the use of recursion and condition checks to solve these problems effectively.

Uploaded by

Anime Z
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

// pick

if ( [Link]() == 0 || nums[index] >= [Link]() ) {


cur.push_back(nums[index]);
helper(cur,index+1,ans,nums);
cur.pop_back();
}

// not pick
if ( [Link]() == 0 || nums[index] != [Link]() )
helper(cur,index+1,ans,nums);
for ( int k = 0; k < 9; k++ )
if ( board[i][k] == val || board[k][j] == val )
return false;
int solve( int row, vector<int> &config) {

if ( row == confi[Link]() )
return 1;

int count = 0;

for ( int col = 0; col < confi[Link](); col++ ) {


config[row] = col;
if ( ok(row,config) )
count += solve(row+1,config);
config[row] = -1;
}

return count;

}
int paths(int i,int j, vector<vector<int>> &grid, vector<vector<int>> &vis, int remaining_nodes) {

if ( i < 0 || i >= [Link]() || j < 0 || j >= grid[0].size() || grid[i][j] == -1 || vis[i][j] == 1 )


return 0;

You might also like