zoukankan      html  css  js  c++  java
  • 1326

    1326 - Race
    Time Limit: 1 second(s) Memory Limit: 32 MB

    Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, Munsiji came into their life. Munsiji took them to derby (horse racing). Munsiji enjoyed the race, but as usual Disky and Sooma did their as usual task instead of passing some romantic moments. They were thinking- in how many ways a race can finish! Who knows, maybe this is their romance!

    In a race there are n horses. You have to output the number of ways the race can finish. Note that, more than one horse may get the same position. For example, 2 horses can finish in 3 ways.

    1. Both first
    2. horse1 first and horse2 second
    3. horse2 first and horse1 second

    Input

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

    Each case starts with a line containing an integer n (1 ≤ n ≤ 1000).

    Output

    For each case, print the case number and the number of ways the race can finish. The result can be very large, print the result modulo 10056.

    Sample Input

    Output for Sample Input

    3

    1

    2

    3

    Case 1: 1

    Case 2: 3

    Case 3: 13


    Problem Setter: Md. Mahbubul Hasan
    Special Thanks: Shahriar Rouf Nafi, Tanaeem M Moosa, Jane Alam Jan
    思路:裸的斯特林数
     1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<string.h>
     4 #include<iostream>
     5 using namespace std;
     6 typedef long long LL;
     7 const LL N= 10056;
     8 LL yan[1005][1005];
     9 LL STL[1005][1005];
    10 LL pp[1005];
    11 LL quick(LL n,LL m);
    12 int main(void)
    13 {
    14         int i,j,k;
    15         scanf("%d",&k);
    16         int s;
    17         yan[0][0]=1;
    18         for(i=1; i<=1000; i++)
    19         {
    20                 for(j=0; j<=i; j++)
    21                 {
    22                         if(j==0||i==j)
    23                                 yan[i][j]=1;
    24                         else
    25                         {
    26                                 yan[i][j]=(yan[i-1][j]+yan[i-1][j-1])%N;
    27                         }
    28                 }
    29         }
    30         pp[0]=1;
    31         for(i=1;i<=1000;i++)
    32             pp[i]=(pp[i-1]*i)%N;
    33         memset(STL,0,sizeof(STL));
    34         STL[0][0]=1;
    35         STL[1][0]=0;
    36         STL[1][1]=1;
    37         for(i=2; i<=1000; i++)
    38         {
    39                 for(j=1; j<=i; j++)
    40                 {
    41                         if(j==1||i==j)
    42                                 STL[i][j]=1;
    43                         else
    44                         {
    45                                 STL[i][j]=((STL[i-1][j]*j)%N+STL[i-1][j-1])%N;
    46                         }
    47                 }
    48         }
    49         for(s=1; s<=k; s++)
    50         {    int x1;
    51                 scanf("%d",&x1);
    52                 LL cnt=0;
    53                 for(i=1; i<=x1; i++)
    54                 {
    55                     cnt=(cnt+(STL[x1][i]*pp[i])%N)%N;
    56                 }
    57                 printf("Case %d: ",s);
    58                 printf("%lld
    ",cnt);
    59         }
    60         return 0;
    61 }
    62 
    63 LL quick(LL n,LL m)
    64 {
    65         LL ans=1;n%=N;
    66         while(m)
    67         {
    68                 if(m&1)
    69                         ans=(ans*n)%N;
    70                 n=(n*n)%N;
    71                 m/=2;
    72         }
    73         return  ans;
    74 }
    油!油!you@
  • 相关阅读:
    在Chrome浏览器中保存的密码有多安全?
    进程上下文切换 – 残酷的性能杀手(上)
    进程上下文切换 – 残酷的性能杀手(下)
    javascript推荐书籍
    使用Visual Studio 利用WinGDB编译和远程调试嵌入式Linux的程序
    Source Insight 3.X 标签插件v1.0发布
    QQ空间自动发广告解决方法
    Java---实力弹弹球,弹弹弹
    HDOJ 2027 统计元音
    Java---计算机贷款支付额计算(用对话框实现)
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5447499.html
Copyright © 2011-2022 走看看