Relative Content

Tag Archive for data-structuresdynamic-programming

why this code is giving error in solve_spo function but not in other function use . the solve_spo function is derived from the solve_tabu function

int solve_tabu(int N ,int arr[],int t){ vector<vector<int>> dp(t+1,vector<int>(N+1,0)); for(int i=0;i<=N;i++){ dp[0][i]=1; } for(int Target=0;Target<=t;Target++){ for(int index=N-1;index>=0;index–){ int choice1=0; if(Target-arr[index]>=0) choice1=dp[Target-arr[index]][index+1]; //do not choose int choice2=dp[Target][index+1]; dp[Target][index]= max(choice1,choice2); } } return dp[t][0]; } int solve_spo(int N, int arr[], int t) { vector<int> curr(t + 1, 0); vector<int> next(t + 1, 0); next[0] = 1; // Initialize […]