Re: 10130 - SuperSale
Posted: Tue Nov 24, 2015 12:45 am
why this get wrong answer..im getting right output for all input case
here is my code
here is my code
Code: Select all
#include<bits/stdc++.h>
using namespace std;
int n,profit1,profit2;
int dpi[101][101],cost[1000],weight[1000],cap;
int dp(int i,int w)
{
if(i==n+1)
return 0;
if(dpi[i][w]!=-1)
return dpi[i][w];
int profit1=0,profit2=0;
if(w+weight[i]<=cap)
profit1=cost[i]+dp(i+1,w+weight[i]);
profit2=dp(i+1,w);
dpi[i][w]=max(profit1,profit2);
return dpi[i][w];
}
int main()
{
int t;
scanf("%d",&t);
for(int m=1;m<=t;m++)
{
int sum=0;
scanf("%d ",&n);
for(int i=1;i<=n;i++)
{
scanf("%d %d",&cost[i],&weight[i]);
}
int g;
scanf("%d",&g);
for(int k=0;k<g;k++)
{
memset(dpi,-1,sizeof(dpi));
scanf("%d",&cap);
sum+=dp(1,0);
}
printf("%d\n",sum);
}
return 0;
}