ZZULI 1595 Pills

Pills

Time Limit:1000MS  Memory Limit:65536K
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个半粒药丸有几种吃法,数据不大,水过……

 

代码:

#include<stdio.h>
__int64 sum [ 65 ][ 65 ] = { 0 };
__int64 W( int m , int n)
{
              if( sum [ m ][n ] != 0)
                              return sum [ m ][n ];
              else {

              if(n == 0)
                              return W( m - 1 ,n + 1);
              else {
                              return W( m - 1 ,n + 1) + W( m ,n - 1);
              }
              }
}
int main()
{
              int i , j ,n;
              for( i = 1; i <= 60; i ++)
                              sum [ 0 ][ i ] = 1;
              for( i = 1; i <= 30; i ++)
                              for( j = 0; j <= 30; j ++)
                                              if( i + j / 2 <= 30)
                                              sum [ i ][ j ] = W( i , j);
              while( scanf( "%d" , &n ),n != 0 ){
                              printf( "%I64d \n " , sum [n ][ 0 ]);
              }
}
 
下面写出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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值