CF148E Porcelain

LIsa

就是一个背包

#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
#define int long long
using namespace std;
template<class T>inline void read(T &x)
{
    x=0;register char c=getchar();register bool f=0;
    while(!isdigit(c))f^=c=='-',c=getchar();
    while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
    if(f)x=-x;
}
template<class T>inline void print(T x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar('0'+x%10);
}
int l[10005],r[10005];
int n,m;
int k;
int a[10005];
int f[105][10005];
signed main(){
	//ios::sync_with_stdio(false);
	read(n);read(m);
	for(int i=1;i<=n;++i){
		read(k);
		for(int j=1;j<=k;++j){
			read(a[j]);
		}
		r[k+1]=0;
		for(int j=1;j<=k;++j){
			l[j]=l[j-1]+a[j];
		}
		for(int j=k;j>=1;--j){
			r[j]=r[j+1]+a[j];
		}
		for(int j=0;j<=min(m,k);++j){
			int tem=0;
			for(int z=0;z<=j;++z){
				tem=max(tem,l[z]+r[k-(j-z)+1]); 
			}
		//	cout<<tem<<endl;
			for(int z=j;z<=m;++z){
				f[i][z]=max(f[i][z],f[i-1][z-j]+tem);
			}
		}
	}
	cout<<f[n][m];
    return 0;
}

posted @ 2021-10-12 15:56  Simex  阅读(35)  评论(0编辑  收藏  举报