Pills
Time Limit:1000MS
Total Submit:13 Accepted:9
Description
Aunt Lizzie takes half a pill of a certain medicine every day. She starts with a bottle that contains N pills.
On the first day, she removes a random pill, breaks it in two halves, takes one half and puts the other half back into the bottle.
On subsequent days, she removes a random piece (which can be either a whole pill or half a pill) from the bottle. If it is half a pill, she takes it. If it is a whole pill, she takes one half and puts the other half back into the bottle.
In how many ways can she empty the bottle? We represent the sequence of pills removed from the bottle in the course of 2N days as a string, where the i-th character is W if a whole pill was chosen on the i-th day, and H if a half pill was chosen (0 <= i < 2N). How many different valid strings are there that empty the bottle?
Input
The input will contain data for at most 1000 problem instances. For each problem instance there will be one line of input: a positive integer N <= 30, the number of pills initially in the bottle. End of input will be indicated by 0.
Output
For each problem instance, the output will be a single number, displayed at the beginning of a new line. It will be the number of different ways the bottle can be emptied.
Sample Input
6 1 4 2 3 30 0
Sample Output
132 1 14 2 5 3814986502092304
Source
这算是今年开学以来第一次比赛了,虽然数据比较弱,但是也反映了自己上学期落下了好多的东西,算是给自己的警醒吧,以后努力……
题目大意:一个瓶子里面有n个药丸,每次只能吃半粒,所以第一次只能取一粒然后吃半粒把剩余的半粒放到瓶子里,后面既可以取半粒吃掉,也可以取一粒剩下半粒,这样的话就有好多种选择了(天文数字……),问瓶子里面有n粒药丸的时候一共有多少种吃法?
这个题刚拿到的时候以为是有公式的,可是推了半天也没有推出来,后来一怒之下就想暴力解决了,没想到还竟然真过了,当然,暴力也是需要优化的(看来一切皆暴力也是有一定道理的啊,只不过是时间问题),直接递归,然后把已经找到过的直接赋值用数组存储下来,比如a[i][j]代表现在瓶子里面有i个整粒药丸和j个半粒药丸有几种吃法,数据不大,水过……
代码:
__int64 sum [ 65 ][ 65 ] = { 0 };
__int64 W( int m , int n)
{
}
int main()
{
}
下面写出1到30的测试数据:
1
1
2
2
3
5
4
14
5
42
6
132
7
429
8
1430
9
4862
10
16796
11
58786
12
208012
13
742900
14
2674440
15
9694845
16
35357670
17
129644790
18
477638700
19
1767263190
20
6564120420
21
24466267020
22
91482563640
23
343059613650
24
1289904147324
25
4861946401452
26
18367353072152
27
69533550916004
28
263747951750360
29
1002242216651368
30
3814986502092304