Answers for "how to initialize 2d vector with 0"

C++
1

how to initialized a 2d vector

To be used in DP problems:

vector<vector<int>>dp; //global init

dp = vector<vector<int>>(n,vector<int>(m,0)); // local init for test cases
where,
	n, m = dimensions of matrix
Posted by: Guest on August-24-2021
1

size of a matrix using vector c++

// finding size of a square matrix
myVector[0].size();
Posted by: Guest on June-25-2020
5

initialising 2d vector

// Initializing 2D vector "vect" with 
// values 
vector<vector<int> > vect{ { 1, 2, 3 }, 
                           { 4, 5, 6 }, 
                           { 7, 8, 9 } };
Posted by: Guest on May-16-2020
1

c++ 2D vectors

int main() 
{ 
    int row = 5; // size of row 
    int colom[] = { 5, 3, 4, 2, 1 }; 
  
    vector<vector<int> > vec(row);  // Create a vector of vector with size equal to row. 
  	for (int i = 0; i < row; i++) { 
  		int col;  
        col = colom[i]; 
  		vec[i] = vector<int>(col); //Assigning the coloumn size of vector
        for (int j = 0; j < col; j++) 
            vec[i][j] = j + 1; 
    } 
  
    for (int i = 0; i < row; i++) { 
        for (int j = 0; j < vec[i].size(); j++) 
            cout << vec[i][j] << " "; 
        cout << endl; 
    } 
}
Posted by: Guest on July-27-2020

Code answers related to "how to initialize 2d vector with 0"

Browse Popular Code Answers by Language