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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//**************************************************************************************
ll ans[maxn];
void pre()
{
ans[]=;
for(int i=;i<maxn;i++)
ans[i]=ans[i-]*,ans[i]%=mod;
}
ll fac[maxn];
ll qpow(ll a,ll b)
{
ll ans=;a%=mod;
for(ll i=b;i;i>>=,a=a*a%mod)
if(i&)ans=ans*a%mod;
return ans;
}
ll C(ll n,ll m)
{
if(m>n||m<)return ;
ll s1=fac[n],s2=fac[n-m]*fac[m]%mod;
return s1*qpow(s2,mod-)%mod;
}
int main()
{
fac[]=;
for(int i=;i<maxn;i++)
fac[i]=fac[i-]*i%mod;
pre();
int n=read();
ll ans1=;
for(int i=;i<=n;i++)
{
ans1+=(ans[n-i]-)*C(n,i);
ans1%=mod;
}
cout<<ans1<<endl;
}
Codeforces Gym 100187D D. Holidays 排列组合的更多相关文章
- Codeforces 991E. Bus Number (DFS+排列组合)
解题思路 将每个数字出现的次数存在一个数组num[]中(与顺序无关). 将出现过的数字i从1到num[i]遍历.(i from 0 to 9) 得到要使用的数字次数数组a[]. 对于每一种a使用排列组 ...
- CodeForces - 817B(分类讨论 + 排列组合)
题目链接 思路如下 这一题是:最菜的队伍只有三个人组成,我们只需对排序后的数组的 前三个元素进行分类讨论即可: a[3] != a[2] && a[3] != ar[1] a[3] = ...
- codeforces 57 C Array(简单排列组合)
C. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls 排列组合
C. Kyoya and Colored Balls Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...
- Codeforces 140E(排列组合、dp)
要点 主要学到的东西:一个序列染色,相邻不染同色,恰用\(j\)种颜色的1.模式数.2.方案数.3.具体染色数. 从大的思路上来讲:先dp预处理出每一层的模式数:\(f[i][j]\)表示\(i\)个 ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- [Codeforces 997C]Sky Full of Stars(排列组合+容斥原理)
[Codeforces 997C]Sky Full of Stars(排列组合+容斥原理) 题面 用3种颜色对\(n×n\)的格子染色,问至少有一行或一列只有一种颜色的方案数.\((n≤10^6)\) ...
- 【CodeForces】914 H. Ember and Storm's Tree Game 动态规划+排列组合
[题目]H. Ember and Storm's Tree Game [题意]Zsnuoの博客 [算法]动态规划+排列组合 [题解]题目本身其实并不难,但是大量干扰因素让题目显得很神秘. 参考:Zsn ...
- 【CodeForces】889 C. Maximum Element 排列组合+动态规划
[题目]C. Maximum Element [题意]给定n和k,定义一个排列是好的当且仅当存在一个位置i,满足对于所有的j=[1,i-1]&&[i+1,i+k]有a[i]>a[ ...
随机推荐
- Drupal如何更新注册表?
Drupal的注册表是指registry和registry_file两个数据表.前一个表保存所有可用的类和接口以及它们所对应的文件,后一个表保存每个文件的hash码. 1. 将所有需要更新的文件都汇总 ...
- [转]Linux之type命令
转自:http://codingstandards.iteye.com/blog/831504 用途说明 type命令用来显示指定命令的类型.一个命令的类型可以是如下之一 alias 别名 keywo ...
- 序列for循环语句
序列for循环语句 序列for循环语句允许重复遍历一组序列,而这组序列可以是任何可以重复遍历的序列,如由begin()和end()函数定义的STL序列.所有的标准容器都可用作这种序列,同时它也同样可以 ...
- 3 years in Tencent game
心里一直有继续写博文的愿望,却一直被各种借口打断,现在回头一看,已经在腾讯待了3年半之久.3年半是个比较尴尬的时间点,不好意思说自己是游戏从业老兵,但又觉得自己对于行业已经看到比较清楚了:从当年毕业时 ...
- 【LeetCode】36 - Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.(http://sudoku.com.au/TheRu ...
- KMP算法的代码实现
上周算法班的BEN老师花了1个小时讲自动机和KMP的关系,结果failed...明天又要上课了,花了半天时间看了下KMP,暂且停留在利用next求模式中的跳跃长度,自动机那个还不能理解... 具体的可 ...
- 怎么去掉Xcode工程中的某种类型的警告
XCode警告 问题描述 在我们的项目中,通常使用了大量的第三方代码,这些代码可能很复杂,我们不敢改动他们,可是作者已经停止更新了,当sdk升级或者是编译器升级后,这些遗留的代码可能会出现许许多 ...
- win7启动出现蓝屏STOP: 0X0000007B
解决方法:开机进BIOS,更改Interface Combination,即硬盘的接口种类,由默认的RAID改成了AHCI,保存,重启,一切正常. 事件过程: 今天开机进入win7,在start wi ...
- 怎样下载完整的Spring包
自从3.2版本以后,Spring不再提供包含所有库的文件下载了只有Sping自身的最基本库,所依赖的东西需要自己搞定首先, 这个链接 包含了Spring自身和所用到的所有东西 这个 是上述链接的说 ...
- VBA
1.ActiveWorkbook是Application对象的一个属性,表示的是一个active Workbook. 2.Application对象可以获得一些顶级的对象,比如ActiveCell,A ...