[Codeforces 1579G] Minimal Coverage | dp最小区间覆盖

简介: 题意: 给出n个线段,以及一个无限大的坐标轴,第一个线段以0为起点进行放置,后面的线段必须以前一个的终点为起点放置,这就有两种方式,向左向右

You are given n lengths of segments that need to be placed on an infinite axis with coordinates.
The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate 0. Let’s call this endpoint the “start” of the first segment and let’s call its “end” as that endpoint that is not the start.
The “start” of each following segment must coincide with the “end” of the previous one. Thus, if the length of the next segment is d and the “end” of the previous one has the coordinate x, the segment can be placed either on the coordinates [x−d,x], and then the coordinate of its “end” is x−d, or on the coordinates [x,x+d], in which case its “end” coordinate is x+d.
The total coverage of the axis by these segments is defined as their overall union which is basically the set of points covered by at least one of the segments. It’s easy to show that the coverage will also be a segment on the axis. Determine the minimal possible length of the coverage that can be obtained by placing all the segments on the axis without changing their order.
Input
The first line contains an integer t ( 1 ≤ t ≤ 1000 ) — the number of test cases.
The next 2t lines contain descriptions of the test cases.
The first line of each test case description contains an integer n ( 1 ≤ n ≤ 1 0 4 ) — the number of segments. The second line of the description contains n space-separated integers a i ( 1 ≤ a i ≤ 1000 ) — lengths of the segments in the same order they should be placed on the axis.
It is guaranteed that the sum of n over all test cases does not exceed 10 4 .
Output
Print t lines, each line containing the answer to the corresponding test case. The answer to a test case should be a single integer — the minimal possible length of the axis coverage.
Example
inputCopy

相关文章
|
10月前
|
数据采集 算法 大数据
大数据中噪声数据处理
【10月更文挑战第20天】
1604 2
|
机器学习/深度学习 数据采集 数据挖掘
使用sklearn高效进行数据挖掘,收藏!
使用sklearn高效进行数据挖掘,收藏!
64 5
|
存储 弹性计算 固态存储
2023阿里云服务器租用价格表(优惠报价和官方收费标准)
阿里云服务器租用价格表包括ECS共享型s6、通用算力型u1、计算型c6、计算型c7、通用型g6、通用型g7及GPU云服务器等,包括云服务器ECS实例CPU内存价格、公网带宽价格和系统盘收费标准
2569 0
2023阿里云服务器租用价格表(优惠报价和官方收费标准)
SDUTOJ2498---AOE网上的关键路径
SDUTOJ2498---AOE网上的关键路径
SDUTOJ2498---AOE网上的关键路径
|
7天前
|
人工智能 运维 安全
|
5天前
|
人工智能 异构计算
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
敬请锁定《C位面对面》,洞察通用计算如何在AI时代持续赋能企业创新,助力业务发展!
|
6天前
|
机器学习/深度学习 人工智能 自然语言处理
B站开源IndexTTS2,用极致表现力颠覆听觉体验
在语音合成技术不断演进的背景下,早期版本的IndexTTS虽然在多场景应用中展现出良好的表现,但在情感表达的细腻度与时长控制的精准性方面仍存在提升空间。为了解决这些问题,并进一步推动零样本语音合成在实际场景中的落地能力,B站语音团队对模型架构与训练策略进行了深度优化,推出了全新一代语音合成模型——IndexTTS2 。
576 20