连续递增子串最长长度的数学期望

参考

【1】:

longest consecutive subsequence of a random permutation

    第一个帖子:    

    Theorem: The expected length of the longest increasing block in a random permutation of {1,2,,n} is r0(n)+O(1) as n, where r0(n) is the smallest positive integer such that r0(n)!>n. ("Block" means consecutive subsequence ai+1,ai+2,,ai+r for some i and r, with no conditions on the relative sizes of the ai.)

    证明反正也没看懂我也就不说啥了,结论是:r + C,其中 r是 r!>n的最小正整数,C是一个常数。(但是很奇怪程序运算起来和这个结论略有出入)

    第二个帖子说:子串长度r大概是这个函数增长的,r=log(n)/W(log(n)/e),因为W函数比Log增长略慢,所以r增长比logn/loglogn略快,并非如猜想的~logn。

【2】:

LISBOOK   (如果是非连续的子串的话,长度趋近与2√n)

 

正文

    偶然翻微博看到2013年问桑爷一个问题。如果一个随机的数数列,长度是是L,其元素是1-L不重复。问这个数列的连续递增子串的最长的长度的数学期望是多少?比如13254的最长连续递增子串是25,长度就是2。

    当时我算了好久啊,没算出来……当然至今也没算出来,昨天写了个小程序算了一下。

    打乱排序的函数用了库函数random_shuffle(...):

    

random_shuffle( int *A, int L);

 

    求解的函数非常简单,扫一遍得到结果。

 1 int calc(int *A,int L){
 2     int max = 1;
 3     int cur = 1;
 4     
 5     if(!L) return 0;
 6     For(i,L-1){
 7         if(A[i+1] >= A[i] ){
 8             cur++;
 9             max = max>cur?max:cur;
10         }else{
11             cur = 1;
12         }
13     }
14     return max;
15 }

    于是得到如下结果:

    

图一:横轴:数列长度n,纵轴平均长度E

其中0<=n<=350000

    看上去增长貌似是lg级的啊,于是重新算一下,取对数看看。

图二:n=10,10^2,10^3...10^9.

图三:图二的散点图

    猜想平均期望是 ~log(n)的了,不过正如文章开头所提,其实是~logn/loglogn。

    学数学人的脑子真变态。。。

posted on 2015-03-09 05:58  L.W.L  阅读(694)  评论(0编辑  收藏  举报

导航