-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path2020-A-B.cpp
49 lines (38 loc) · 946 Bytes
/
2020-A-B.cpp
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
#include<bits/stdc++.h>
using namespace std;
void solve(){
int N,K,P;
cin >> N >> K >> P;
vector<vector<pair<int,int>>> a(N,vector<pair<int,int>>());
for(int i=0 ; i<N ; ++i)
{
int val;
cin >> val;
a[i].push_back(make_pair(1, val));
for(int j=1 ; j< K ; ++j){
int x;
cin >> x;
val += x;
a[i].push_back(make_pair(j+1,val));
}
}
// vector<vector<int>> dp(P,vector<int>(a.size(),0));
// for(int i=0)
vector<int> dp(P+1,0);
for(int i=0 ; i< N ; ++i)
for(int v = P ;v >=0 ; --v){
for(const auto& e : a[i])
if(v >= e.first)
dp[v] = max(dp[v], dp[v - e.first] + e.second);
}
cout << dp[P] << "\n";
}
int main(){
int T;
cin >> T;
for(int t =1 ; t <= T ; ++ t){
cout << "Case #"<<t<<": ";
solve();
}
return 0;
}