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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include <iostream> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <unordered_map> #include <string> #include <cmath> #include <set> #include <stack> #include <vector> #include <deque> #include <bitset> #include <cstdio> #include <iomanip>
#define ull unsigned long long #define ed '\n' #define fi first #define se second #define fore(i, l, r) for(int i = (int)(l); i <=(int)r; i++) #define debug(x) cout << "#x = " << x << ed; #define PI acos(-1) #define E exp(1) #define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define me0(st) memset(st, 0, sizeof st) #define me3f(st) memset(st, 0x3f, sizeof st) #define pdf(x) printf("%lf", double(x)) #define pif(x) printf("%d ", int(x)) #define scf(x) printf("%d", int(x)) #define re return 0
#define out(x, k) cout << fixed << setprecision(k) << x << ed
using namespace std;
typedef pair<int, int> PII; typedef long long LL; typedef double db;
const int INF = 1e9; const int N = 510, M = 5e3 + 10; int a[N], b[N], c[N]; LL ans = INF; int n, k;
int dp[N][M][2];
void solve() { memset(dp, -1, sizeof dp); int n, k; cin>> n >> k; fore (i, 1, n) cin >> a[i]; fore (i, 1, n) cin >> b[i]; fore (i, 1, n) cin >> c[i]; dp[0][0][0] = 0; fore (i, 0, n){ fore (j, 0, 5010){ if(dp[i][j][0] != -1){ dp[i + 1][j + c[i + 1]][1] = max(dp[i + 1][j + c[i + 1]][1], dp[i][j][0] + a[i + 1] * b[i + 1] ); if(dp[i][j][0] >= a[i + 1] * b[i + 1]){ dp[i + 1][j][0] = max(dp[i + 1][j][0] , dp[i][j][0]); } } if(dp[i][j][1] != -1){ dp[i + 1][j + c[i + 1]][1] = max(dp[i + 1][j + c[i + 1]][1], dp[i][j][1] + a[i + 1] * b[i + 1]); if(dp[i][j][1] >= a[i + 1] * b[i + 1]){ dp[i + 1][j][0] = max(dp[i + 1][j][0] , dp[i][j][1]); } } } } bool flag = true; fore (i, 0, 5000){ if(dp[n][i][0] >= k || dp[n][i][1] >= k){ cout << i << ed; flag = false; break; } } if(flag){ cout << "chu ti zhe ying gai xue yi xia e long" << ed; } }
int main() { int _ = 1; cin >> _; while(_--) { solve(); } return 0; }
|