Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 10157: Expressions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10157: Expressions 解題者:張庭愿 解題日期: 2009 年 8 月 16 日 題意:所有的括號必須成對,且必須先出現過左 括號後才能出現右括號,如果有.

Similar presentations


Presentation on theme: "1 10157: Expressions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10157: Expressions 解題者:張庭愿 解題日期: 2009 年 8 月 16 日 題意:所有的括號必須成對,且必須先出現過左 括號後才能出現右括號,如果有."— Presentation transcript:

1 1 10157: Expressions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10157: Expressions 解題者:張庭愿 解題日期: 2009 年 8 月 16 日 題意:所有的括號必須成對,且必須先出現過左 括號後才能出現右括號,如果有 d 層括號,深度 則為 d 。 2 ≦ n ≦ 300 , 1 ≦ d ≦ 150 。 現在給定兩個數: n 與 d , n 為左括號加右括號的 數量, d 為要求的深度。問在長度為 n 的括號中, 深度為 d 的合理組合有幾種。

2 2 題意範例: Sample input: 6 2 300 150 Output for sample input: 3 1 (())() ()(()) (()())

3 3 解法: 利用推導出來的公式,將所有的解先存起 來以供之後利用,並且要注意大數。 公式: F(n,d) =0if n<0 or d<0 1if n=0 and d ≧ 0 ΣF(n-2,d-1)*F(n-k,d)otherwise 2 ≦ k ≦ n and k is even F(n,d) 之值為長度 n 的情況,深度 d 以下之組 合總合,故 F(n,d) - F(n,d-1) 即是要求 d 組合 數之解答。


Download ppt "1 10157: Expressions ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10157: Expressions 解題者:張庭愿 解題日期: 2009 年 8 月 16 日 題意:所有的括號必須成對,且必須先出現過左 括號後才能出現右括號,如果有."

Similar presentations


Ads by Google