Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstring>
- using namespace std;
- typedef long long ll;
- const int maxn = 22;
- int n, m, k;
- int opening_cost[maxn];
- int rating[maxn][maxn], cost[maxn][maxn];
- int dp[maxn][1005][2];
- int rec(int at_batch, int money_left, bool is_locked) {
- if(at_batch >= n) {
- return 0;
- }
- if(dp[at_batch][money_left][is_locked] != -1) {
- return dp[at_batch][money_left][is_locked];
- }
- int real_money = money_left;
- if(is_locked) {
- real_money -= opening_cost[at_batch];
- }
- int res = 0;
- if(real_money >= 0) {
- for(int i = 0; i < m; i++) {
- if(real_money >= cost[at_batch][i]) {
- res = max(res, rec(at_batch, real_money - cost[at_batch][i], false) + rating[at_batch][i]);
- res = max(res, rec(at_batch + 1, real_money - cost[at_batch][i], true) + rating[at_batch][i]);
- }
- }
- }
- res = max(res, rec(at_batch + 1, money_left, true));
- return dp[at_batch][money_left][is_locked] = res;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- int T;
- cin >> T;
- while(T--) {
- cin >> n >> m >> k;
- for(int i = 0; i < n; i++) {
- cin >> opening_cost[i];
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> cost[i][j];
- }
- }
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> rating[i][j];
- }
- }
- memset(dp, -1, sizeof dp);
- cout << rec(0, k, true) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement