Category : error-handling

I’ve been trying to learn dynamic programming on c++, and this is my first project on that (knapsack problem) Please help me understand why I’m getting these errors. This is my code: #include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int knap(int n, int wt[], int price[], int W){ // n = number of items; size ..

Read more

I am trying to sort a vector of integers using selection method. I am using vector::begin() to iterate over the elements of the vector, however, something is wrong in the iteration that make such an error as below: What is the problem here? #include<iostream> #include<vector> void selection_sort(std::vector<int> vec); int main(){ std::vector<int> vec = {2 , ..

Read more

I have the following code: #include <iostream> #include <vector> #include <cstring> #include <math.h> #include <bits/stdc++.h> using namespace std; void solver(vector<int> arr,int leng,vector<bool> &res){ if (arr.size() == 0){ res.push_back(false); } int square = 0; for(int i = 0;i<leng;i++){ if (i == 0){ square = arr[i]; }else if(i > 0){ square = square*arr[i]; } } float root ..

Read more