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;
}

Codeforces Gym 100187D D. Holidays 排列组合相关推荐

  1. Codeforces 991E. Bus Number (DFS+排列组合)

    解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...

  2. CodeForces 630 I. Parking Lot(排列组合)

    有 2*n-2 个车位 ,有 4 种车,车可以看作为无穷多,当且仅当 n 辆相同种类的车挨在一起时,老板会很开心,问有多少种方式让老板开心 对于每种车而言: 有 n 辆放在停车场的两端时,此时还剩 n ...

  3. [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)

    [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...

  4. [Codeforces 893E. Counting Arrays]排列组合

    [Codeforces 893E. Counting Arrays]排列组合 分类:combinatorics number theory math 1. 题目链接 [Codeforces 893E. ...

  5. java 穷举 排列组合,JavaScript递归穷举所有排列组合并找出重复值

    null export default { data() { return { resultArr:[] } }, mounted(){ this.sss('aaba','abac'); this.s ...

  6. php 1到9加,php通过排列组合实现1到9数字相加都等于20的方法

    摘要:本文实例讲述了php通过排列组合实现1到9数字相加都等于20的方法.分享给大家供大家参考.具体实现方法如下:<?php set_time_limit(0); /* 函数说明:huoqu_z ...

  7. 论排列组合,持续更新

    今天刚好碰到了一个排列组合问题,因为之前对这方面的学习比较少,所以用的非常蠢的方法做了四位数中取三位的排列,写的程序太有局限性,源码如下 #define _CRT_SECURE_NO_WORNINGS ...

  8. 无重复字符串的排列组合

    无重复字符串的排列组合.编写一种方法,计算某字符串的所有排列组合,字符串每个字符均不相同. 示例1: 输入:S = "qwe" 输出:["qwe", " ...

  9. 【牛客每日一题】4.16 逆序对 ( 数学 , 排列组合 ,快速幂 , 快速乘 )

    [每日一题]逆序对 链接:https://ac.nowcoder.com/acm/problem/14731 来源:牛客网 题目描述 求所有长度为n的01串中满足如下条件的二元组个数: 设第i位和第j ...

最新文章

  1. networkx的基本使用
  2. 百度地图API公交检索示例 - 标绘结果路线、返回结果集
  3. 【FI 收付款条件】Payment Terms 收付款条件
  4. 向Window窗体发送消息,控制程序的运行.
  5. FZU2020 lucas定理求解组合数
  6. Cisco路由器——Console线的接法
  7. java heap space flex_Flash builder 4内存优化之java heap space解决办法
  8. 关于webSocket建立前后端连接,并进行心跳机制的实现
  9. Hadoop入门(二十)Mapreduce的最小值程序
  10. jpanel把原本内容覆盖掉_暖冬遇上倒春寒,花被大雪覆盖,小心一夜回到解放前...
  11. jQuery size()函数
  12. ESP8266 驱动步进电机(28BYJ-48电机 ULN2003 驱动板)
  13. pymysql操作MySQL数据库表-----爬虫豆瓣top250电影并存入数据库
  14. 学生个人html静态网页制作 基于HTML+CSS+JavaScript+jquery仿苏宁易购官网商城模板
  15. 第九篇:稳定性之面向失败设计【可用性架构设计、可用性容灾】
  16. 【迟到的Java岗面经】面7家,意外收获5家意向offer,越努力越幸运!
  17. A. Equalize Prices Again(水题) Codeforces Round #590 (Div. 3)
  18. iTron3学习笔记(一) System Calls of Memory Pool Management Functions
  19. MySQL:安装软件和基本操作
  20. 光纤网卡千兆和万兆、光口和电口之间的区别?与PC网卡、HBA卡的区别有哪些?

热门文章

  1. notepad怎么设置python为环境变量_notepad
  2. 1.1 版本控管与Git
  3. java 前端导出exvel_java导出数据到Excel文件 前端进行下载
  4. python rindex()_Python3 rindex()方法
  5. Python 根据文件绝对路径删除文件
  6. Spring Data Jpa的@Temporal注解
  7. Windows环境下Docker常用命令
  8. Java中Minio基础使用
  9. Spring Cloud基础入门
  10. CentOS7中解决root用户Operation not permitted