Tags: ,.

部分和序列,往往是我们关注的一种东西,例如下面的题目:

问题描述:给定一个含有 n 个元素的数列,元素有正有负,找出和最小的一组相邻的数。即给定 a[n],求 i,j 使得 a[i] + a[i+1] + ...+ a[j] 的和最小。

转化为和序列:S[1],S[2]...S[n],求$latex Min: S_{[j]}-S_{[i]}$,具体的可以参考Solrex的文章,这个问题给我们的愉悦主要体现在后来的min max 的转换上。
下面我想再举一个例子来说明如何做这类部分和序列问题

Problem Description:
一个拳击手在75天的赛季里,每天都要最少打一场比赛,但是整个赛季不能打超过125场比
赛。那么,我们可以证明,可以从赛季中选出连续的K天,使得这K天的比赛总场数是30场。

这个是个很有趣的问题,我们可以证明,不仅仅是30,甚至是所有小于等于30的场次都可以通过上面的方法选出来。

分析:
抽象成数学问题:

$latex X_{[k]}$ $latex \in$ $latex \mathbb{N}$,$latex X_{[k]}$ $latex \geq 1 $, $latex \sum_{k=1}^{75} X_{[k]}\leq 125$

Prove: Exist $latex i,j$ ($latex j \geq i$),S.T. $latex \sum_{k=i}^j X_{[k]} =30$

首先,这是个部分和序列的问题,如果要用累加这种相对朴素的方法直接求解部分和序列的问题会使问题变得复杂化。那么转化为和序列是个好主意。
令$latex S_{[i]}= \sum_{k=1}^i X_{[k]}$,那么就是要证明存在$latex i,j$,使得$latex S_{[j]}-S_{[i]}=30$;

下面就是这个题目精彩的地方了:构造抽屉,{1,31},{2,32},...{61,91}{62,92}..{90,120}{121}{122}{123}{124}{125},每个{}内为一个抽屉,共有65个抽屉,要从中选出75个数,必然有一个抽屉内的两个数被选出来了,哈,这不是最朴素的那种抽屉原理么。
所以问题得以解决。

反过来思考这个问题,还是有那么点意思的:-)
1. 部分和序列转化为和序列的差。
2. 巧妙的构造抽屉

下期预告:
马尔可夫过程的首达及其应用:-)




Comments

Good.Be the first to comment on this entry.

Post comment

comment has COPYRIGHT too!

Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).