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[ ...
随机推荐
- 【转】loadrunner检查点设置
转自:http://www.cnblogs.com/fnng/archive/2013/03/10/2953257.html 判断脚本是否执行成功是根据服务器返回的状态来确定的,如果服务器返回的HTT ...
- 企业高并发的成熟解决方案(一)video(笔记&知识点)
知识点 答案 什么是高可用(HA) 高并发发生在哪两处 app服务器会出现什么问题,有哪些解决方案? 数据库并发有什么要求? hadoop集群的作用 负载均衡的功能有哪些 负载均衡的分类 哪种负载均衡 ...
- jquery、js操作checkbox全选反选
全选反选checkbox在实际应用中比较常见,本文有个不错的示例,大家可以参考下 操作checkbox,全选反选//全选 function checkAll() { $('input[name=&qu ...
- div模拟的下拉框特效
随笔- 4 文章- 0 评论- 0 ? <style type="text/css"> body, ul, li { margin: 0; padding: 0; fo ...
- Python状况:为什么PyPy是Python的未来?
Python 现在已经不仅仅是胶水脚本语言了. 不信?看看下面使用Python的成功案例: YouTube - 主要由 Python编写 NASA Industrial Light & Mag ...
- Eralng 小知识点
文件属性 提取方法:Module:module_info/1 头文件 包含头文件 -include(FileName). %% FileName为绝对路径或相对路径 引入库中包含文件 -include ...
- 【多线程】Java线程面试题 Top 50(转载)
Java线程面试题 Top 50 原文链接:http://www.importnew.com/12773.html 本文由 ImportNew - 李 广 翻译自 javarevisited.欢迎 ...
- 3.VS2010C++相关文件说明
stdafx.h说明:stdafx的英文全称为:Standard Application Framework Extensions(标准应用程序框架的扩展).所谓头文件预编译,就是把一个工程(Proj ...
- hdu 5424 Rikka with Graph II (BestCoder Round #53 (div.2))(哈密顿通路判断)
http://acm.hdu.edu.cn/showproblem.php?pid=5424 哈密顿通路:联通的图,访问每个顶点的路径且只访问一次 n个点n条边 n个顶点有n - 1条边,最后一条边的 ...
- oracle数据库连接字符串
不在项目加入tsname.ora的托管写法: <add name="CONN" connectionString="data source=127.0.0.1:15 ...