#89 D

problem link http://codeforces.com/contest/118/problem/D

2011-10-9

21:38 It seems this problem is about enumeration of combination.

21:42 Using DP.

21:44 If I had already get F(n-1), means in total n-1 units, there are F(n-1) kinds of beautiful arrangements.

    suppose the beautiful arrangement is xxxxxxxxxxxx, x means unit, then put a new unit on the right will form a new arrangement.

    let f means footman unit, h means horseman unit. and k1 = 3 , k2 = 5

    then xxxxxxxxxfff arrange dosen't allow adding f to the right, because that would destroy the beautiful arrangement.

    same for xxxxxxxhhhhh . (21:50)

     so F(n) = F(n-1) - K1(n-1) - K2(n-1)  where K1(n-1) means the amount of beautiful arrangement in the form of xxxxxxxxxfff ( K2(n-1) for xxxxxxxhhhhh ) (21:53)

22:03 I found this clue will be complicated, because two function K1 and K2 are not easy to evaluate. Another clue is consider

    xxxxxxxxxff + f;  xxxxxxxxxxf + f; xxxxxxxxxxxx + f 

    xxxxxxxxhhhh + h; xxxxxxxxxhhh + h; xxxxxxxxxxhh + h; xxxxxxxxxxxh + h; xxxxxxxxxxxx + h;

    redefine K1(n) and K2(n) .

    K1(n) is the amount of beautiful arrangement that has total n units which last one unit are not f.  

    K2(n) is the amount of beautiful arrangement that has total n units which last one unit are not h.    (22:09)

    Now, F(n) = K1(n-1) + K1(n-2) + K1(n-3) + K2(n-1) + K2(n-2) + K3(n-3) + K4(n-4) + K5(n-5) + K5(n-6). 

    For abstraction, F(n) = K1(n-1) + K1(n-2) + ... + K1(n-k1) + K2(n-1) + K2(n-2) + ... + K2(n-k2)   (22:13)

      OK, now the key is to figure out the representation of K1(n) and K2(n) (22:15)

22:19 According to the definition of K1(n), means the last one unit must be h, so K1(n) = F(n-1) (n-1 unit plus one h), and K2(n) is the same.

22:29 Some detail to notice, F(n) will lost the counter part of the running out unit.

2011-10-10

11:51 The solution I consider yesterday can't satisfy the restriction of unit number limit.

    The new solution is base on the old one, let's define the following function.

    F1(n) : total n units, and the nth unit is f unit, F1(n) represents the number of such beautiful arrangement.

    F2(n) : similar to F1(n), the only difference is the nth unit is h unit, not f unit.

    F1(n) = F2(n-1) + F2(n-2) + ... + F2(n-k1)     (xxxxxhf  + xxxxhff + xxxhfff ...)

    F2(n) = F1(n-1) + F1(n-2) + ... + F1(n-k2)

    in fact, this two equation is not something new, they still can't satisfy the restriction I mention above.

    The new concept is:

    F1(n, m) : total n units, the nth unit is f unit, and there are m f unit inside the total n 

    F2(n, m) : similar to F1(n, m)

      remind that k1 = 3, k2 = 5

      F1(n, 1) = F2(n-1, n-1) 

        F1(n, 2) = F2(n-1, n-2) + F2(n-2, n-2)

      F1(n, 3) = F2(n-1, n-3) + F2(n-2, n-3) + F2(n-3, n-3)

      F1(n, 4) = F2(n-1, n-4) + F2(n-2, n-4) + F2(n-3, n-4) (no F2(n-4, n-4), because k1 = 3, at most 3 f unit at right most )

      ....

      F1(n, n-1) = F2(n-1, 1) + F2(n-2, 1) + F2(n-3, 1) 

      F1(n, n) = 1 or 0 ( if n > k1 then 0 )  (12:22)

2011-10-11

17:21

   Came across a problem, what should be the value of F1(0, 0) and F2(0, 0),  consider when calculating F1(n,n), I choose 1 anyway.

     Accepted! But for the first submission, I upload the the source code of another problem -___-...

posted @ 2011-10-11 17:27  DOF_KL  阅读(523)  评论(0编辑  收藏  举报