File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+
5
+
6
+
7
+ void solve (){
8
+ int N,K,P;
9
+ cin >> N >> K >> P;
10
+ vector<vector<pair<int ,int >>> a (N,vector<pair<int ,int >>());
11
+
12
+ for (int i=0 ; i<N ; ++i)
13
+ {
14
+ int val;
15
+ cin >> val;
16
+ a[i].push_back (make_pair (1 , val));
17
+ for (int j=1 ; j< K ; ++j){
18
+ int x;
19
+ cin >> x;
20
+ val += x;
21
+ a[i].push_back (make_pair (j+1 ,val));
22
+ }
23
+ }
24
+
25
+ // vector<vector<int>> dp(P,vector<int>(a.size(),0));
26
+
27
+ // for(int i=0)
28
+ vector<int > dp (P+1 ,0 );
29
+
30
+ for (int i=0 ; i< N ; ++i)
31
+ for (int v = P ;v >=0 ; --v){
32
+ for (const auto & e : a[i])
33
+ if (v >= e.first )
34
+ dp[v] = max (dp[v], dp[v - e.first ] + e.second );
35
+ }
36
+ cout << dp[P] << " \n " ;
37
+ }
38
+
39
+ int main (){
40
+ int T;
41
+ cin >> T;
42
+
43
+ for (int t =1 ; t <= T ; ++ t){
44
+ cout << " Case #" <<t<<" : " ;
45
+
46
+ solve ();
47
+ }
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments