getting incorrect answer
ide: https://ide.codingblocks.com/s/198298
0-N Knapsack DP
@Vishal123
Your code had some minor indexing issues which were merely due to carelessness. I have corrected it and attached the link
I was not able to save it on this ide.codingblock.com so i have attached a ideone link. Just in case you cannot access it . i am also copy pasting the AC code.
#include<bits/stdc++.h>
#define mod 1000000007
#define pp pair<ll,ll>
#define mp make_pair
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
ll dp[1010][1010],n,cap,wt[1010],val[1010];
int main(){
memset(dp,0,sizeof(dp));
cin>>n>>cap;
for(int i=1;i<=n;i++)
cin>>wt[i];
for(int i=1;i<=n;i++)
cin>>val[i];
for(int i=1;i<=cap;i++){
for(int j=1;j<=n;j++){
dp[i][j] = dp[i][j-1];
if(i-wt[j]>=0)
dp[i][j] = max({dp[i][j] , val[j] + dp[i-wt[j]][j-1],val[j]+dp[i-wt[j]][j]});
}
}
cout<<dp[cap][n];
return 0;
}