Codeforces Round #315-Codeforces Round #315(贝尔数)

题目地址:New Language
题意:求1到n,n个元素组成的集合中,满足对称性和传递性但不满足自反性的二元组关系集合的个数。
思路:对于每组的对应关系中,正好满足贝尔数(其实是贝尔三角形每行的和)
这里写图片描述
由图中红框中可以发现上一行的总和=下一行的n-1位置上的数。然后其实上贝尔数的板子就好了。

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;
typedef long long LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-6;
const int maxn=4010;
const int mod=1e9+7;
LL dp[maxn][maxn];
int main()
{
    dp[0][0]=1;
    for(int i=1;i<maxn;i++){
        dp[i][0]=dp[i-1][i-1]%mod;
        for(int j=1;j<maxn;j++){
            dp[i][j]=((dp[i][j-1]+dp[i-1][j-1])%mod+mod)%mod;
        }
        }
    int n;
        while(~scanf("%d",&n)){
            printf("%lld\n",dp[n][n-1]);
        }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rocky0429

一块也是爱

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值