#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using lld= long double;
#define v vector
#define pb push_back
#define FF first
#define SS second
#define ALL(a) a.begin(), a.end()
#define LINIJKI ios_base::sync_with_stdio(0);cin.tie(0)
int main()
{
LINIJKI;
ll ile, wielk, brac;
cin>>ile>>wielk>>brac;
v<ll>dp(brac+1, 0);
v<ll>pref(wielk+1);
for(ll i=0;i<ile;i++){
pref[0] = 0;
for(ll j=0;j<wielk;j++){
cin>>pref[j+1];
pref[j+1] += pref[j];
}
for(ll j=brac;j>=0;j--){
for(ll k=1;k<=min(j, wielk);k++){
dp[j] = max(dp[j], dp[j-k] + pref[k]);
}
}
}
cout<<dp[brac]<<"\n";
}
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 | #include<bits/stdc++.h> using namespace std; using ll=long long; using lld= long double; #define v vector #define pb push_back #define FF first #define SS second #define ALL(a) a.begin(), a.end() #define LINIJKI ios_base::sync_with_stdio(0);cin.tie(0) int main() { LINIJKI; ll ile, wielk, brac; cin>>ile>>wielk>>brac; v<ll>dp(brac+1, 0); v<ll>pref(wielk+1); for(ll i=0;i<ile;i++){ pref[0] = 0; for(ll j=0;j<wielk;j++){ cin>>pref[j+1]; pref[j+1] += pref[j]; } for(ll j=brac;j>=0;j--){ for(ll k=1;k<=min(j, wielk);k++){ dp[j] = max(dp[j], dp[j-k] + pref[k]); } } } cout<<dp[brac]<<"\n"; } |
English