预处理每个架子上打坏n个的最大毁坏值,就转化成经典的分组背包问题了.......
import java.util.*;
public class Porcelain {
static int n, m;
static int[] s = new int[110];
static int[][] sum = new int[110][110];
static int[][] dem = new int[110][110];
static int[][] dp = new int[110][11000];
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
n = in.nextInt();
m = in.nextInt();
for (int i = 1; i <= n; i++) {
s[i] = in.nextInt();
for (int j = 1; j <= s[i]; j++) {
int x = in.nextInt();
sum[i][j] = sum[i][j - 1] + x;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= s[i]; j++) {
int t = 0;
for (int left = 0; left <= j; left++) {
int right = j - left;
int temp = sum[i][left] + sum[i][s[i]] - sum[i][s[i] - right];
t = Math.max(t, temp);
}
dem[i][j] = t;
}
}
for (int i = 1; i <= n; i++) {
for (int j = m; j >= 0; j--) {
for (int k = 0; k <= s[i] && k <= j; k++) {
dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - k] + dem[i][k]);
}
}
}
System.out.println(dp[n][m]);
}
}