01背包+打印路径——Optimal Slots

这篇博客介绍了一个如何为公共活动大厅的最佳时间分配选择事件的程序设计问题。目标是最大化利用时间并减少空闲时间。输入包含事件的持续时间,需要找到能最佳填充给定时间的事件组合。输出应包含选定事件的持续时间和它们的总和。解决方案涉及从后往前选择价值最大的事件,并确保字典序最小。
摘要由CSDN通过智能技术生成

E - Optimal Slots

The main hall of your residency is open for use by the local community and public. Since it was built on public donations, there is no charge of using it. Every weekend particularly on public holidays there are up to 50 reservations to use it for multiple events with different durations.

You have been assigned by the residents to develop a program in choosing events to get most out of allocation time per weekend and have as short unused time as possible. Program should find the event(s) which fill(s) the allocation time best and print it in the same sequence as appears in the reservation list.

Input
Each test case consist of a single line.

The line starts with two integer T and N which is the time allocated for the hall to be used in the particular weekend and the number of events. The next T integer are the durations of the events (as appear in the reservation list). For example from the first line in sample data: T=5 hours, N, number of events =5, first event lasts for 1 hour, second is 2 hours, third is 3 hours, fourth is 4 hours, and the last one is 5 hours.

The input process will be terminated by a line containing 0.

Output
For each line of input value, in a single line, first, output a list of integers which are the selected events duration and another integer which is the sum of the selected events duration.

If there are multiple possible list of events, events that appear earlier in the list takes priority.

题解:

江哥给我说的要字典序最小,所以当时也没想太多。尬笑.jpg。思路就是从后往前拿,后面尽可能拿价值大的这样才能保证字典序最小。然后从前往后判断路径的时候看是不是那个状态转移过来的就好了。是的话就直接打印出来。

#include <bits/stdc++.h>
#define int long long
using namespac
风光柴储微电网最优化经济调度模型是一种用于优化风光柴储微电网系统运行的经济性调度模型。该模型基于matlab yalmip cplex平台,能够对电网系统进行调度,以实现最优的经济性运行。 模型的核心代码如下: ```matlab % 定义变量 P_wind = sdpvar(1,24); % 风电功率 P_solar = sdpvar(1,24); % 太阳能功率 P_battery_charge = sdpvar(1,24); % 电池充电功率 P_battery_discharge = sdpvar(1,24); % 电池放电功率 P_load = sdpvar(1,24); % 用电负荷功率 % 定义约束条件 Constraints = [P_wind + P_solar + P_battery_charge - P_battery_discharge == P_load, P_battery_charge <= P_battery_max_charge, P_battery_discharge <= P_battery_max_discharge, P_battery_charge + P_battery_discharge <= P_battery_max_power]; % 定义目标函数 Objective = sum(P_wind*wind_price + P_solar*solar_price - P_battery_charge*battery_charge_price + P_battery_discharge*battery_discharge_price - P_load*load_price); % 定义优化问题 optimize(Constraints, Objective); % 获取最优解 Optimal_Power = value([P_wind, P_solar, P_battery_charge, P_battery_discharge, P_load]); ``` 该模型通过对风光柴储微电网系统中各种电力资源的供需进行优化调度,以最大化系统运行效益并降低成本。通过matlab yalmip cplex平台,能够快速高效地求解出最优的调度方案,为风光柴储微电网系统的经济运行提供了强有力的支持。 通过该模型,可以使风光柴储微电网系统在满足用电需求的同时,最大限度地利用可再生能源,并合理调配电池的充放电功率,以达到经济性最优化。这对于提高可再生能源的利用率,降低电网运行成本具有重要的意义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值