其中一个测试点
input:
2 100 1000
329 759 613 859 65 926 552 624 660 448 469 454 596 711 280 452 401 173 435 844 316 52 897 4300 9134 582 150 574 754 271 60 623 8439 38 4079 763 407 7672 299 119 210 853 841 670 212 105 341 53 994 12 299 15 265 291 4213 890 616 572 6894 6152 225 990 563 319 740 759 9277 857 171 491 297 884 735 60 631 427 402 13 134 851 235 557 7238 776 61 98 477 8998 536 20 875 295 471 342 733 547 624 232 374 188
567 3682 1000 1000 626 251 1000 1000 2985 3732 1000 566 5357 1000 1000 1000 1000 371 511 1000 50 53 1000 1000 1000 955 15 1000 1687 1000 268 48 1000 300 1000 1000 1000 4328 1000 612 282 1000 1000 1000 1000 550 1000 464 1000 2 1603 97 13 1291 1000 1000 1000 1000 1000 1000 184 1000 1000 1000 1000 794 2588 1000 140 420 507 831 1000 531 1000 1000 220 92 384 1000 1000 629 1000 1000 11 368 343 2272 1000 4 1000 130 1000 107 402 860 1000 1000 1000 1286
output:
9497
代码:
/*
卫风·芄兰
芄兰之支,童子佩觿.
虽则佩觿,能不我知?
容兮遂兮,垂带悸兮.
芄兰之叶,童子佩韘.
虽则佩韘,能不我甲?
容兮遂兮,垂带悸兮.
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul tuple<int,int,int>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rep_(i,a,b) for(int i=a;i>=b;--i)
#define all(x) x.begin(),x.end()
#define bp(x) __builtin_popcountll(x)
#define ctz(x) __builtin_ctzll(x)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define lc (rt<<1)
#define rc (rt<<1|1)
mt19937_64 rnd(time(0));
const int N=3e2+5,yyx=1e9+7;
vector<int> to[N];
int n,m,t,a[N];
int dp[N][N],f[N][N],b[N][N];
int mx;
inline int mod(int x){
return (x%yyx+yyx)%yyx;
}
inline int cmin(int &x,int y){
return x>y?x=y,1:0;
}
inline int cmax(int &x,int y){
return x<y?x=y,1:0;
}
int dfs(int x,int sum){
if(x>t) return 0;
int ma=0,cnt=0;
rep(i,0,n) rep(j,0,sum) dp[i][j]=0;
rep(i,1,n){
rep(j,0,sum){
dp[i][j]=dp[i-1][j];
if(j>=b[x][i]) cmax(dp[i][j],dp[i][j-b[x][i]]+b[x+1][i]);
cmax(ma,dp[i][j]+sum-j);
}
}
//ma+=sum-cnt;
cout<<x<<" "<<ma<<endl;
//cmax(ma,sum);
cmax(mx,ma);
dfs(x+1,ma);
return ma;
}
inline void solve(){
cin>>t>>n>>m;
//vector<vector<int>> b(t+5,vectot<int>(n+5,0));
rep(i,1,t) rep(j,1,n) cin>>b[i][j];
dfs(1,m);
cout<<mx<<endl;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
//freopen("D://321//in.txt","r",stdin);
//freopen("D://321//out.txt","w",stdout);
int _=1;
//cin>>_;
while(_--)
solve();
return 0;
}