Kattis Problem - Radio Commercials

这是一篇关于Kattis Problem - Radio Commercials的动态规划解题分析。文章介绍了如何找到一个连续的时间段来播放广告,使得收益最大化。题意是给定n个时间段和每个广告的费用p,每观看一次广告收益1元。通过动态规划策略,确定以每个时间段为结束点时的最大收益,并用一个变量来优化状态转移。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Kattis Problem - Radio Commercials

题目类型:动态规划

原题链接

题意

给定 n 个连续的时间段期间收看广告的人的数量,和发布一个广告所需要的费用 p,假设每有一个人收看广告则会有一元的收益。现在需要找一个连续的播放广告的时间段子序列使收益总和最大。

分析

dp[i] 是以第 i 段结尾的收益的最大和
状态转移
如果 dp[i - 1] < 0 则说明 dp[i-1]dp[i] 做负贡献,即 dp[i-1] + a[i] < a[i]。所以
dp[i-1] > 0 时:dp[i] = dp[i-1] + a[i]
dp[i-1] < 0 时: dp[i] = a[i]
因为状态转移只用到 dp[i-1] 所以可以使用一个变量进行维护。具体细节参考代码。

代码
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
   

    static final int MAX_N = 100010;
    static final int INF = 0x3f3f3f3f;
    static final int mod = 
MP3 Splitter &amp; Joiner Pro v5.1 22 March 2012 released Products MP3 Splitter &amp; Joiner MP3 Splitter &amp; Joiner Pro Audio Recorder Platinum Audio Recorder Pro MIDI MP3 Converter MP3 Audio Converter MP3 CD Ripper Special Offering Get 30% discount now if you are the registered user of MP3 Splitter &amp; Joiner Go &gt;&gt; Product News 22 March, 2012 MP3 Splitter &amp; Joiner Pro v5.10 released - Fixed some minor bugs 25 March, 2011 MP3 Splitter &amp; Joiner Pro v5.00 released - Support to split WMA, APE, FLAC, OGG file - Support to merge APE, FLAC file - MP3 Splitter Pro: new designed output naming feature 28 January, 2011 MP3 Splitter &amp; Joiner Pro v4.31 released - Fixed some compatibility issues on Windows Vista and Windows 7. 30 December, 2010 MP3 Splitter &amp; Joiner Pro v4.30 released - Supports to load audio files to split or merge in Windows Explorer directly: right-click the files (including *.cue, *. pls, *.m3u ), and select to open with MP3 Splitter &amp; Joiner Pro in &#39;open with&#39; menu. - MP3 Splitter Pro: Improve the split by silence feature, it is able to detect the silence length even in 10ms (minimum silence length). - Fixed some minor bugs. 17 May, 2009 MP3 Splitter &amp; Joiner Pro v4.22 released - Improve the compatibility of generated audio file: some of split or merged audio files can not be successfully loaded by Windows Media Player. - MP3 Joiner Pro: automatically free the source audio file while setting the output ID3 tag. - Fixed some minor bugs. Testimonials &quot;...I am very satisfied with the product. It is very simple, and easy to use, as well as quick. Also, being able to split files both by time, or into equal segments is a very handy feature..&quot; - David &quot;...I am taking 4 hour radio shows that I have in WAV format, converting to mp3, editing the commercials out, and storing on my iPod. Your program is very intuitive and after
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值