#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); } }
আমার ব্লগে আপনাকে স্বাগতম...... আমি সুভাশিষ মল্লিক... পড়াশোনা করছি কুষ্টিয়ার ইসলামী বিশ্ববিদ্যালয়ের কম্পিউটার সায়েন্স এন্ড ইঞ্জিনিয়ারিং বিভাগে... প্রোগ্রামিং করতে অনেক ভালো লাগে আর তার চেয়েও বেশি ভালো লাগে প্রোগ্রামিং এর যেকোনো কাজে কাওকে সাহায্য করতে,আর সেই জন্যই আমার এই ব্লগ... আপনার জন্যই আমার এই ব্লগ... নিজে প্রোগ্রামিং করুন ও অন্যকে প্রোগ্রামিং করতে উৎসাহ প্রদান করুন.... Happy Coding
মঙ্গলবার, ২৩ মে, ২০১৭
UVA 10130 - SuperSale
এতে সদস্যতা:
মন্তব্যগুলি পোস্ট করুন (Atom)
Factory Pattern
Factory Method is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...
-
In the first example the maximum product is achieved for 389 389 (the product of digits is 3 ⋅ 8 ⋅ 9 = 216 3 ⋅ 8 ⋅ 9 = 216 ). In the s...
-
#include<bits/stdc++.h> using namespace std; int main() { int ts; cin>>ts; getchar(); while(ts--) {...
-
INPUT: 1 5 1 4 2 6 8 10 3 4 7 10 OUTPUT: Case 1: 4 For each case, print the case number and the number of post...
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন