SDUT2883 Hearthstone//Stirling

第五届省赛:Hearthstone

组合数学。

n个比赛,m个桌子(n>=m)。每个比赛一个桌子,每个桌子至少使用一次。

拿到题之后的思路一直是n个位置如何填满m个桌子。

其实是道stirling数模型,直接套公式 m!*{n m}

#include <stdio.h>
#include<string.h>
#define L 1000000007
int main(){
    int n,m;
    long long a[101];
    while(scanf("%d%d",&n,&m)!=EOF){
        a[0]=0;
        for (int i=1;i<=n;i++)
            a[i]=1;
        for (int i=3;i<=n;i++)
            for (int j=i-1;j>0;j--)
                a[j]=(j*a[j]%L+a[j-1])%L;
        for (int i=1;i<=m;i++)
            a[m]=((a[m]%L)*i)%L;
        printf("%lld\n",a[m]);

    }
    return 1;
}

一开始没过,后来把数组开成long long就行了>_<

时间: 2024-08-08 22:04:38

SDUT2883 Hearthstone//Stirling的相关文章

组合计数 &amp;&amp; Stirling数

参考: http://blog.csdn.net/qwb492859377/article/details/50654627 http://blog.csdn.net/acdreamers/article/details/8521134 http://blog.csdn.net/sr_19930829/article/details/40888349 球,盒子都可以分成是否不能区分,和能区分,还能分成是否能有空箱子,所以一共是8种情况,我们现在来一一讨论. 1.球同,盒不同,无空箱 C(n-1,

HDU5816 Hearthstone(状压DP)

题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5816 Description Hearthstone is an online collectible card game from Blizzard Entertainment. Strategies and luck are the most important factors in this game. When you suffer a desperate situation an

Stirling公式

n!与    的值十分接近,利用Stirling公式将阶乘转化成幂函数,使得阶乘的结果得以更好的估计.而且n越大,估计得就越准确 用该公式计算n!结果的位数时,可以两边取对数,得: #include<iostream> #include<math.h> using namespace std; const double e=2.7182818284590452354,pi=3.141592653589793239; //e和i的值要精确 double str_ling(int n)

杭电OJ第十五届ACM第一题 Hearthstone

Problem Description   Cdfpysw loves playing a card game called "Hearthstone".   Now he has N cards, he wants to split these cards into 4 piles. Let's assume the number of cards in each pile is a1, a2, a3, a4.   It must be satisfied that:     a1

HDU4372-Count the Buildings(第一类Stirling数+组合计数)

Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 171 Problem Description There are N buildings standing in a straight line in the City, numbere

HDU 4372 Count the Buildings:第一类Stirling数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看可以看到b栋楼,并且高的楼会挡住低的楼. 问你这些楼有多少种排列方法. 题解: 由于高的楼会挡住低的楼,所以这些楼首先会被划分成f+b-2个区域(除去中间最高的楼),并且左边有f-1个,右边有b-1个. 对于一个区域(假设在左边),这个区域由若干栋楼组成,并且最高的楼一定在最左边. 那么,由一个区域

lightoj1326_第二类Stirling

题目链接http://lightoj.com/volume_showproblem.php?problem=1326 1051 - Good or Bad    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB A string is called bad if it has 3 vowels in a row, or 5 consonants in a row, or both. A strin

Bell(hdu4767+矩阵+中国剩余定理+bell数+Stirling数+欧几里德)

Bell Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4767 Description What? MMM is learning Combinatorics!? Looks like she is playing with the bell sequence now: bell[n] = number of ways to part

贝尔数(来自维基百科)&amp; Stirling数

贝尔数 贝尔数以埃里克·坦普尔·贝尔(Eric Temple Bell)为名,是组合数学中的一组整数数列,开首是(OEIS的A000110数列): Bell Number Bn是基数为n的集合的划分方法的数目.集合S的一个划分是定义为S的两两不相交的非空子集的族,它们的并是S.例如B3 = 5因为3个元素的集合{a, b, c}有5种不同的划分方法: {{a}, {b}, {c}} {{a}, {b, c}} {{b}, {a, c}} {{c}, {a, b}} {{a, b, c}}; B0