zoukankan      html  css  js  c++  java
  • hdu Examining the Rooms

    这道题的知识点第一次听说 ,就是应用斯特林数。题目的意思是给你房间数N,和最多能破门的个数,让你求能全部把房间打开的概率!

    a[i][j]=a[i-1][j-1]+(i-1)*a[i-1][j];

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <algorithm>
     5 using namespace std;
     6 
     7 long long f[30],a[30][30];
     8 
     9 void inti()
    10 {
    11     f[1]=1;
    12     f[0]=1;
    13     for(int i=2; i<=20; i++)
    14     {
    15         f[i]=f[i-1]*i;
    16     }
    17     for(int i=1; i<=20; i++)
    18     {
    19         a[i][0]=0;
    20     }
    21     for(int i=1; i<=20; i++)
    22     {
    23         for(int j=1; j<=i; j++)
    24         {
    25             if(i==j) a[i][j]=1;
    26             else
    27                 a[i][j]=a[i-1][j-1]+(i-1)*a[i-1][j];
    28         }
    29     }
    30     for(int i=1; i<=20; i++)
    31     {
    32         for(int j=1; j<=20; j++)
    33         {
    34             a[i][j]=abs(a[i][j]);
    35         }
    36     }
    37 }
    38 
    39 int main()
    40 {
    41     int t,n,k;
    42     scanf("%d",&t);
    43     inti();
    44     while(t--)
    45     {
    46         scanf("%d%d",&n,&k);
    47         long long sum=0;
    48         for(int i=1; i<=k; i++)
    49         {
    50             sum+=(a[n][i]-a[n-1][i-1]);
    51         }
    52         printf("%.4lf
    ",sum*1.0/f[n]);
    53     }
    54     return 0;
    55 }
    View Code
  • 相关阅读:
    Lucky Substrings
    KMP
    圆桌问题(hdu4841)
    codeforces 624C Graph and String
    Joseph(hdu1443)
    The Longest Straight(FZUoj2216)
    C1. 组队活动 Small(BNUOJ)
    A1. 道路修建 Small(BNUOJ)
    Problem 2221 RunningMan(fuzoj)
    CODEFORCEs 621E. Wet Shark and Blocks
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3661898.html
Copyright © 2011-2022 走看看