OFFSET
1,2
COMMENTS
a(n) is the value such that for any permutation P of n elements, P always contains a unimodal subsequence of length a(n), i.e., a sequence that is increasing, or decreasing, or increasing then decreasing.
n appears floor((2n+1)/3) = A004396(n) times. - Peter Kagey, Feb 27 2021
LINKS
Peter Kagey, Table of n, a(n) for n = 1..10000
F. R. K. Chung, On unimodal subsequences, Journal of Combinatorial Theory, Series A, 279 (1980), pp. 267-279.
FORMULA
a(n) = ceiling(sqrt(3*n - 3/4) - 1/2).
EXAMPLE
a(3) = 3 because all permutations of 3 elements are unimodal.
a(4) = 3 because there are permutations of 4 elements (e.g., 1423) that are not unimodal, but using the previous value we can always fix that by deleting one element.
MAPLE
MATHEMATICA
Table[Ceiling[Sqrt[3 n - 3/4] - 1/2], {n, 100}] (* Wesley Ivan Hurt, Oct 16 2015 *)
PROG
(C) unsigned int a(unsigned int n) { return ceil( sqrt((double) 3*n - 0.75) - 0.5); }
(PARI) a(n) = ceil(sqrt(3*n-3/4) - 1/2); \\ Michel Marcus, Apr 22 2014
(Magma) [Ceiling(Sqrt(3*n - 3/4) - 1/2) : n in [1..100]]; // Wesley Ivan Hurt, Oct 16 2015
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Anthony Labarre, Mar 15 2013
STATUS
approved