zoukankan      html  css  js  c++  java
  • Codeforces Gym 100187D D. Holidays 排列组合

    D. Holidays

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/gym/100187/problem/D

    Description

    Everyone knows that the battle of Endor is just a myth fabled by George Lucas for promotion of his movie. Actually, no battle of Endor has happened and the First Galactic Empire prospers to this day.

    There are creatures of n races living in the First Galactic Empire. In order to demonstrate their freedom, equality and brotherhood the Emperor commanded to introduce the holidays. During each of these holidays creatures of one non-empty subset of races should give gifts to creatures of another non-empty subset of races, not intersecting the first one.

    The Emperor's stuff is not very strong in maths so you should calculate how many such holidays can be introduced. Two holidays are considered different if they differ in the subset of races which give gifts or in the subset of races which receive gifts.

    Input

    The input contains the only integer n (1 ≤ n ≤ 200000) — the number of races living in the First Galactic Empire.

    Output

    Find the number of holidays the Emperor commanded to introduce. This number can be very large, so output the reminder of division of this number by 109 + 9.

    Sample Input

    2

    Sample Output

    2

    HINT

    题意

    每一个集合都是一个种族,这个种族会给任何与他没有相交的集合礼物,有n个人,问你最后要给几个礼物?

    题解:

    数学题啦,推公式推公式,排列组合就好了

    代码

    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <set>
    #include <vector>
    #include <sstream>
    #include <queue>
    #include <typeinfo>
    #include <fstream>
    #include <map>
    #include <stack>
    typedef long long ll;
    using namespace std;
    //freopen("D.in","r",stdin);
    //freopen("D.out","w",stdout);
    #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
    #define test freopen("test.txt","r",stdin)
    #define maxn 2001001
    #define mod 1000000009
    #define eps 1e-9
    const int inf=0x3f3f3f3f;
    const ll infll = 0x3f3f3f3f3f3f3f3fLL;
    inline ll read()
    {
        ll x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    //**************************************************************************************
    ll ans[maxn];
    void pre()
    {
        ans[0]=1;
        for(int i=1;i<maxn;i++)
            ans[i]=ans[i-1]*2,ans[i]%=mod;
    }
    ll fac[maxn];
    ll qpow(ll a,ll b)
    {
        ll ans=1;a%=mod;
        for(ll i=b;i;i>>=1,a=a*a%mod)
            if(i&1)ans=ans*a%mod;
        return ans;
    }
    ll C(ll n,ll m)
    {
        if(m>n||m<0)return 0;
        ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
        return s1*qpow(s2,mod-2)%mod;
    }
    int main()
    {
        fac[0]=1;
        for(int i=1;i<maxn;i++)
            fac[i]=fac[i-1]*i%mod;
        pre();
        int n=read();
        ll ans1=0;
        for(int i=1;i<=n;i++)
        {
            ans1+=(ans[n-i]-1)*C(n,i);
            ans1%=mod;
        }
        cout<<ans1<<endl;
    }
  • 相关阅读:
    澄净是什么意思?
    【Cavali风格/优质羊毛混纺面料/高密抗静电里衬/撞色拼皮/立领/绿色/便装单西】玛萨玛索男装网购商城
    【100%纯新美利奴羊毛(除装饰材料外)/半高领/丈青/商务毛衫】玛萨玛索男装网购商城
    victim是什么意思_victim在线翻译_英语_读音_用法_例句_海词词典
    Lind.DDD.Repositories.EF层介绍
    Lind.DDD.Domain领域模型介绍
    大叔也说Xamarin~Android篇~原生登陆与WebView的网站如何共享Session
    Redis学习笔记~Redis并发锁机制
    知方可补不足~sqlserver中对xml类型字段的操作
    json转String 和 String转json 和判断对象类型
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4657529.html
Copyright © 2011-2022 走看看