• 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@
  • 相关阅读:
    18款 非常实用 jquery幻灯片图片切换
    6款强大的 jQuery 网页布局创建及优化插件
    18 个最新实用的 jQuery 插件
    jQuery中的编程范式
    JQuery _ 定时器(jQuery Timers) 学习
    21个最佳jQuery插件推荐
    7 款基于 JavaScript/AJAX 的文件上传插件
    C#
    kernel 3.10内核源码分析--hung task机制
    进程的虚拟地址空间
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5447499.html
Copyright © 2020-2023  润新知