-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path697D.cpp
More file actions
75 lines (65 loc) · 1.31 KB
/
Copy path697D.cpp
File metadata and controls
75 lines (65 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <bits/stdc++.h>
using namespace std;
int a[2*100000];
int b[2*100000];
int n;
int dp[2*100000];
// m = a and pos = i hole ami minimum koto pai
int kp(int m, int pos, int w) {
if(m == 0) {
return w;
}
if (pos >= n){
if(m == 0) {
return w;
} else {
return INFINITY;
}
}
if (dp[pos] != -1) return dp[pos];
return dp[pos] = min(kp(m-a[pos],w+b[pos],pos+1),kp(m,w,pos+1));
}
int knapsack(int w, int pos) {
if(w == 0) {}
}
int DP(int m,int w, int pos)
{
if(m <= 0){
return w;
}
if(pos >= n)return 2000000000;
if(dp[pos]!= -1)return dp[pos];
else
{
dp[pos] = min(DP(m-a[pos],w+b[pos],pos+1),DP(m,w,pos+1));
printf("%d --- > %d\n",pos,dp[pos]);
return dp[pos];
}
}
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++)
{
scanf("%d", &b[i]);
}
memset(dp,-1,sizeof(dp));
int ans = kp(m,0,0);
if(ans==2000000000){
printf("-1\n");
}
else
{
printf("%d\n",ans);
}
}
}