当前位置:网站首页>[Best training DAY16] KC's Can [Dynamic programming]
[Best training DAY16] KC's Can [Dynamic programming]
2022-07-30 00:15:00 【六世——MOESR】

思路:
First converted into limited knapsack problem,But the card often card in the past
c o d e code code
#include<iostream>
#include<cstdio>
#define re register
using namespace std;
int n, m;
int a[110][110], sum[110][110], p[110][110], f[110][10001], g[10001], s[10001];
int main() {
scanf("%d%d", &n, &m);
for(re int i = 1; i <= n; ++ i) {
scanf("%d", &a[i][0]);
for(re int j = 1; j <= a[i][0]; ++ j)
scanf("%d", &a[i][j]), sum[i][j] = a[i][j] + sum[i][j - 1];
for(re int j = 0; j <= a[i][0]; ++ j) {
p[i][j] = 1e9;
re int q = a[i][0] - j;
for(re int k = 1; k + q - 1 <= a[i][0]; ++ k) {
p[i][j] = min(p[i][j], sum[i][k + q - 1] - sum[i][k - 1]);
}
p[i][j] = sum[i][a[i][0]] - p[i][j];
}
}
for(re int i = 1; i <= n; ++ i) {
for(re int j = 0; j <= a[i][0]; ++ j) {
for(re int k = m; k >= j; -- k) {
if(g[k - j] + p[i][j] > f[j][k]) f[j][k] = g[k - j] + p[i][j];
if(f[j][k] > s[k]) s[k] = f[j][k];
}
}
for(re int k = m; k >= 0; -- k)
g[k] = s[k];
}
printf("%d", g[m]);
return 0;
}
边栏推荐
猜你喜欢

2022年企业直播行业发展洞察

抖音短视频流量获取攻略,掌握好这些一定可以出爆款

重建二叉树

多商户商城系统功能拆解18讲-平台端商家售后

“灯塔工厂”的中国路径:智造从点到面铺开

WeChat developer tools set the tab size to 2

The go language (functions, closures, defer, panic/recover, recursion, structure, json serialization and deserialization)

微信开发者工具设置制表符大小为2

Genesis与Axis Ventures互动密切

NumPy(二)
随机推荐
Go日志库——logrus
Decision tree principle and code implementation
图论:二分图
第一范式、第二范式、第三范式
The difference and usage of call, apply and bind
Worthington用于细胞收获的胰蛋白酶&细胞释放程序
ZLMediaKit源码分析 - NotifyCenter
QTableWidget使用示例
vim相关介绍(二)
直播平台搭建,设置状态栏颜色
How do we-media people create explosive articles?These 3 types of articles are most likely to explode
NumPy(二)
i.MX6U-driver development-3-new character driver
『牛客|每日一题』走迷宫
UE4 makes crosshair + recoil
I.MX6U-驱动开发-3-新字符驱动
窗口函数笔记
绘制几何图形
Worthington dissociating enzyme: detailed analysis of neutral protease (dispase)
【经验】经验总结-经验教训