题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1292

 

分析:
    i代表人数,j代表组数,有dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j。
 解释:
     前者是第i个人自成一队;后者是第i个人并入已有的队列。
  特别的,当i==j的时候:f[i][j]=1;

  这题与hdu2512同样解法。。。

 

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
using namespace std;
LL dp[50][50];
void init()
{
    dp[0][1]=1;
    for(int i=1;i<=25;i++)
    {
        for(int j=1;j<=i;j++)
            dp[i][j]=dp[i-1][j-1]+dp[i-1][j]*j;
    }
}
int main()
{
    int t,n;
    init();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        LL ans=0;
        for(int i=1;i<=n;i++)ans+=dp[n][i];
        printf("%I64d\n",ans);
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2021-10-02
  • 2022-02-10
  • 2022-03-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-03-09
  • 2022-02-26
  • 2021-11-23
相关资源
相似解决方案