zoukankan      html  css  js  c++  java
  • Pills

    #include<iostream>
    #include<cstring>
    using namespace std;

    int N;
    __int64 d[35][35];
    bool m[35][35];

    __int64 Cal(int i, int j)
    {
    if(m[i][j] || j == 0) return d[i][j];
    __int64 r = 0;
    if(i > 0) r += Cal(i - 1, j);
    if(j > 0) r += Cal(i + 1, j - 1);
    d[i][j] = r;
    m[i][j] = 1;
    return r;
    }

    int main()
    {
    int i;
    memset(d, 0, sizeof(d));
    memset(m, 0, sizeof(m));
    for(i = 0; i < 31; i ++) d[i][0] = 1;
    Cal(0, 30);
    while(scanf("%d", &N) != EOF && N != 0)
    {
    printf("%I64d\n", d[0][N]);
    }
    return 0;
    }

    Pills

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


    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
    6 1 4 2 3 30 0
     
    Sample Output
    132 1 14 2 5 3814986502092304
     
    Source
  • 相关阅读:
    第六节:Redis Cluster搭建详解和集群运维(节点、槽位等)
    第七节:Nginx限流和负载均衡、页面cdn、IIS部署优化、后续计划
    第十五节:CAP框架简介和基于CAP实现微服务的事件总线
    【ML】异常点检测
    【产品挖坟】360口信
    【产品】张小龙8小时
    【产品】书单
    【产品】网易云音乐-王诗沐
    【产品思维】拼多多为什么崛起?
    【思考】社交本质
  • 原文地址:https://www.cnblogs.com/xieyue/p/2378565.html
Copyright © 2011-2022 走看看