codeforces 568B B. Symmetric and Transitive(貝爾數+組合數學)__codeforces

來源:互聯網
上載者:User
題目連結:

codeforces 題目大意:

給出n,代表集合元素個數,求出滿足傳遞性和對稱性但不滿足自反性的集合的數目。 題目分析:

我們可以將這個集合看作一個無向圖,也就是對於每個聯通塊當中的點都是滿足這三個性質的。所以所有不符合要求的就是我們選取圖中的一些點(但不能是全部的點),然後對他們進行劃分,也就是集合的劃分的數目。(劃分出的每個集合是一個聯通塊),而集合的劃分數目正好就是貝爾數。 AC代碼:

#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#define MAX 4007using namespace std;typedef long long LL;int n;LL c[MAX][MAX];LL b[MAX][MAX];const LL mod = 1e9+7;void init ( ){    c[0][0] = c[1][0] = c[1][1] = 1;    for ( int i = 2 ; i < MAX ; i++ )        for ( int j = 0 ; j <= i ; j++ )            if ( j == 0 || j == i ) c[i][j] = 1;            else            {                c[i][j] = c[i-1][j] + c[i-1][j-1];                c[i][j] %= mod;            }    b[0][0] = b[1][1] = 1;    for ( int i = 2 ; i < MAX ; i++ )    {        b[i][1] = b[i-1][i-1];        for ( int j = 2 ; j <= i ; j++ )        {            b[i][j] = b[i][j-1] + b[i-1][j-1];            b[i][j] %= mod;        }    }}int main ( ){    init ( );    while ( ~scanf ( "%d" , &n ) )    {        LL ans = 0;        for ( int i = 0 ; i < n ; i++ )        {            ans += c[n][i]*b[i][i]%mod;            ans %= mod;        }        printf ("%I64d\n" , ans );    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.