zoukankan      html  css  js  c++  java
  • LightOJ 1317

    Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %lluDescription

    You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the main game. In our game we were N people trying to throw balls into M identical Baskets. At each turn we all were selecting a basket and trying to throw a ball into it. After the game we saw exactly S balls were successful. Now you will be given the value of N and M. For each player probability of throwing a ball into any basket successfully is P. Assume that there are infinitely many balls and the probability of choosing a basket by any player is 1/M. If multiple people choose a common basket and throw their ball, you can assume that their balls will not conflict, and the probability remains same for getting inside a basket. You have to find the expected number of balls entered into the baskets after K turns.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with a line containing three integers N (1 ≤ N ≤ 16), M (1 ≤ M ≤ 100) and K (0 ≤ K ≤ 100) and a real number P (0 P ≤ 1). P contains at most three places after the decimal point.

    Output

    For each case, print the case number and the expected number of balls. Errors less than 10-6 will be ignored.

    Sample Input

    2

    1 1 1 0.5

    1 1 2 0.5

    Sample Output

    Case 1: 0.5

    Case 2: 1.000000

    程序分析:

    首先我们要知道每一次扔的时候,0个人扔进的概率,1个人扔进的概率….
    由于最后不关心M个篮子里球的具体情况,所以M其实没有什么用
    只要区分扔不扔进去,至于扔到哪个篮子不管
    dp[i][j]表示到第i轮,篮子里有j个球的概率
    最后答案就是Σi?dp[k][i]

    程序代码:

    #include<iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        int t,n,m,k,ans=1;
        double p;
        cin>>t;
        while(t--)
        {
            cin>>n>>m>>k>>p;
            printf("Case %d: %.6lf
    ",ans++, k*n*p);
        }
        return 0;
    }
  • 相关阅读:
    设计模式 创建型 单例模式
    设计模式 创建型 抽象工厂模式
    设计模式六大原则
    设计模式 创建型 工厂方法模式
    设计模式 创建型 简单工厂模式
    Junit TDD
    覆盖索引
    多列索引 单列索引
    JDBC PreparedStatement Statement
    常用·SQL
  • 原文地址:https://www.cnblogs.com/yilihua/p/4749534.html
Copyright © 2011-2022 走看看