zoj How Many Sets I(組合計數),zojsets

來源:互聯網
上載者:User

zoj How Many Sets I(組合計數),zojsets

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4535


一個集合s有n個元素,求滿足這樣的集合序列{s1,s2....sk}使S1 ∩ S2 ∩ ... ∩ Sk = ∅,si是s的子集。


從每個元素考慮會使問題變得簡單。首先n個元素是相互獨立的,單獨考慮第i個元素,它在k個子集的所有情況是2^k,其中有一種情況是k個子集都有第i個元素,這一種情況正好不是我們想要的,所以合法的應該是2^k-1,那麼n個元素就是( 2^k-1 )^n。


#include <stdio.h>#include <iostream>#include <map>#include <set>#include <bitset>#include <list>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>//#define LL __int64#define LL long long#define ULL unsigned long long#define eps 1e-9#define PI acos(-1.0)using namespace std;const LL mod = 1000000007;LL Pow(LL a, LL b){    LL res = 1;    while(b)    {        if(b&1)            res = (res*a)%mod;        b >>= 1;        a = (a*a)%mod;    }    return res;}int main(){    LL n,k;    while(~scanf("%lld %lld",&n,&k))    {        LL res = Pow((LL)2,k);        res -= 1;        res = Pow(res,n);        printf("%lld\n",res);    }    return 0;}





聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.