Hdu 25,121 cartoon Big Adventure (second class sterling number)

Source: Internet
Author: User

The idea of recursion is as follows, I cards are divided into J-piles, then there are two cases: the first card is a bunch of cards or no self-made piles.

Then it's a bunch of dp[i-1][j-1.

Not self-made a bunch of words can be in the J heap arbitrarily pick a bunch of put, so there are dp[i-1][j]*j kind of situation

In summary, the following:

dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1].

On the second kind of Stirling number, Baidu is good.

Specific code

#include <iostream>using namespacestd;intdp[2005][2005];intMain () { for(intI=1; i<= -; i++) {dp[1][i]=0; dp[i][0]=dp[i][1]=1;//use dp[i][0] to store the total possible number of I card storage    }     for(intI=2; i<= -; i++)         for(intj=2; j<= -; j + +) {Dp[i][j]=dp[i-1][j]*j+dp[i-1][j-1]; DP[I][J]%= +; if(dp[i][j]!=0) {dp[i][0]+=Dp[i][j]; dp[i][0]%= +; }    }    intn,t; CIN>>T;  while(t--) {cin>>O; cout<<dp[n][0]<<Endl; }}

Hdu 25,121 cartoon Big Adventure (second class sterling number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.