মঙ্গলবার, ২৩ মে, ২০১৭

UVA 10130 - SuperSale

#include<bits/stdc++.h>
using namespace std;
#define SIZE 1002
int i,n,dp[SIZE][32],wt[SIZE],num[SIZE],qry,chk;
int knap(int i1,int weight)
{
    if(i1==n)
        return 0;
    if(dp[i1][weight]!=-1) return dp[i1][weight];
      dp[i1][weight]=knap(i1+1, weight);
      //int profit1=dp[i1][weight];
    if(weight>=wt[i1])
        dp[i1][weight]=max(dp[i1][weight], num[i1]+knap(i1+1, weight-wt[i1]));
return dp[i1][weight];
}
main()
{
    int ts;
    scanf("%d",&ts);
    while(ts--)
    {
        int sum=0;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            scanf("%d%d",&num[i],&wt[i]);
        }
        memset(dp,-1,sizeof(dp));
        scanf("%d",&qry);
        while(qry--)
        {
           scanf("%d",&chk);
            sum+=knap(0, chk);
        }
         printf("%d\n",sum);
    }
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...