Alll testcases failed

#include<bits/stdc++.h>
using namespace std;

int ansdp(int n,vector&wt,vector&val,int c){
int dp[c+1];
if(n==0){
return 0;

}

memset(dp,0,c+1);

for(int i=0;i<=c;i++){
for(int j=0;j<n;j++){
if(wt[j]<=i){
dp[i] = max(dp[i],dp[i-wt[j]]+val[j]);
}
}
}

return dp[c];

}

int main() {
int n;
cin>>n;
int c;
cin>>c;
vectorwt;
vectorval;
for(int i=0;i<n;i++){
int x;
cin>>x;
wt.push_back(x);

}

	for(int i=0;i<n;i++){
	int y;
	cin>>y;
	val.push_back(y);

}

cout << ansdp(n,wt,val,c) << endl;

}

Your code had some problem with memset(). I have fixed it.
You were setting dp to 0 for size = c+1. but either you have to set for sizeof(dp) which is the size of dp array or you have to set to (c+1)*(sizeof(int)).
@Mohitpandey29

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.