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
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<int> v = {2, 1, 3, 6, 7, 9, 8};
int max = *max_element(v.begin(), v.end());
int min = *min_element(v.begin(), v.end());
std::cout << min << ", " << max << std::endl; // 1, 9
return 0;
}
// to make (n rows x m columns) 2D array, all initialized
// with value 'k' (typeof(k) = T)
vector<vector<T>> vec( n , vector<T> (m, k));
#include<vector>
#include<algorithm>
// all the std and main syntax ofcourse.
vector<int> pack = {1,2,3} ;
// To add at the END
pack.push_back(6); // {1,2,3,6}
// OR
// To add at BEGGINING
pack.insert(pack.begin(),6) // {6,1,2,3,}
vector<vector<int> > v2(8, vector<int>(5));
#include<vector>
#include<algorithm> //**********Have to include THIS...OTHERWISE
sort( vectorName.begin(),vectorName.end() ) ;
// Initializing 2D vector "vect" with
// values
vector<vector<int> > vect{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } };