zoukankan      html  css  js  c++  java
  • HDOJ 4165 Pills

    卡特兰数,打表水过了。

    Pills

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 682    Accepted Submission(s): 446


    Problem 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
    61423300
     

    Sample Output
    132114253814986502092304
     

    Source
     

    Recommend
    lcy


    #include <stdio.h>

    unsigned long long int a[31]={ 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 6564120420, 24466267020, 91482563640, 343059613650, 1289904147324, 4861946401452, 18367353072152, 69533550916004, 263747951750360, 1002242216651368, 3814986502092304};
    int main()
    {
       int n;
       while(scanf("%d",&n)&&n)
       {
           printf("%I64d\n",a[n]);
       }
       return 0;
    }

  • 相关阅读:
    49个128*128像素的天气png图标
    非常漂亮的千千静听皮肤[Warp]出自梦梦的作品
    腾讯的面试题
    什么是函数参数,如何传递函数参数
    我看了这视频,情不自禁的笑了
    WindowBlinds基础使用教程
    晒工资网站
    一个可以搜索word文档,电子表格,PDF,幻灯片的搜索引擎
    网页设计常用png小图标一套
    使用U盘时候的”无法停用通用卷”的解决办法
  • 原文地址:https://www.cnblogs.com/CKboss/p/3351064.html
Copyright © 2011-2022 走看看