POJ 3088
已知n,求n中取k(k<=n)个数组成的m(m<=n)个的集合的排列数.
于是,可以枚举选出k个数及枚举m个集合。这个很明显是二类斯特林数。而集合有序,则乘上m!
#include <iostream>
#include <cstdio>
#include <algorithm>
#define LL __int64
using namespace std; LL con_mul[15],Str[15][15]; void initial(){
con_mul[0]=1;
for(LL i=1;i<=11;i++)
con_mul[i]=con_mul[i-1]*i;
for(LL i=0;i<=11;i++){
for(LL j=0;j<=i;j++){
if(i==j)
Str[i][j]=1;
else if(j==0&&i>=1){
Str[i][j]=0;
}
else{
Str[i][j]=j*Str[i-1][j]+Str[i-1][j-1];
}
// cout<<Str[i][j]<<' ';
}
// cout<<endl;
}
} int main(){
initial();
int n,kase=0;
LL ans,Cnk,t;
scanf("%d",&n);
while(n--){
kase++;
ans=0;
scanf("%I64d",&t);
Cnk=t;
ans+=(Cnk*Str[1][1]);
for(LL i=2;i<=t;i++){
Cnk=Cnk*(t-i+1)/i;
for(LL k=1;k<=i;k++){
ans+=(Cnk*Str[i][k]*con_mul[k]);
}
}
printf("%d %I64d %I64d\n",kase,t,ans);
}
return 0;
}
POJ 3088的更多相关文章
- POJ 3088 斯特林
题意:有一个n个按钮的锁,按下一些按钮打开门,有多少开门方式,其中,一些按钮可以选,可以不选,选中的按钮 可以分成一些集合,集合之间无序,是同时按下的. 分析: 1.首先选择 i 个按钮,组合数 2. ...
- 【noi 2.6_9283】&【poj 3088】Push Botton Lock(DP--排列组合 Stirling数)
题意:N个编号为1~N的数,选任意个数分入任意个盒子内(盒子互不相同)的不同排列组合数. 解法:综合排列组合 Stirling(斯特林)数的知识进行DP.C[i][j]表示组合,从i个数中选j个数的方 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
随机推荐
- [SharePoint][SharePoint Designer 入门经典]Chapter11 工作流基础
1.SPS中可以创建的工作流的种类 2.SPD工作流基础 3.创建列表\库工作流 4.创建可重用的工作流 5.利用基于站点的工作流 6.SPD 工作流的限制和注意事项
- [Angular] Component's dependency injection
An Angular service registered on the NgModule is globally visible on the entire application. Moreove ...
- oracle常见sql语句优化
1.* 号引起的运行效率 尽量降低使用select * 来进行查询,当你查询使用*, 数据库会进行解析并将*转换为所有列. select count(si.student_id) from Stud ...
- hdu(2846)Repository
Problem Description When you go shopping, you can search in repository for avalible merchandises by ...
- HttpClient学习系列 -- 学习总结
jar包: HttpClient 4.x版本 简要介绍 HttpComponents 包括 HttpCore包和HttpClient包 HttpClient:Http的执行http请求 Default ...
- 多年iOS开发经验总结(一)
总结了几个月的东西终于能和大家分享了,不多说,直接看东西! 1.禁止手机睡眠 1 [UIApplication sharedApplication].idleTimerDisabled = YES; ...
- Java-MyBatis-杂项: MyBatis 中 in 的用法2
ylbtech-Java-MyBatis-杂项: MyBatis 中 in 的用法2 1.返回顶部 1. 一.简介 在SQL语法中如果我们想使用in的话直接可以像如下一样使用: select * fr ...
- 捣鼓TinyMCE 粘贴图片并上传+Django后台
前面一篇写了上传到Flask后台,但是我不熟悉Flask,原先想学习一下,据说是轻量级. 但是我发现,学习会浪费我大量的时间,因为我并不是以这个为生的,我的目标只是要完成功能,让我自己能尽早使用起来, ...
- HTML-虚线框3例
第一例: 代码 <HR style=> 第二例: 代码 <DIV style="BORDER-TOP: #00686b 1px dashed; OVERFLOW: hidd ...
- JQuery (总结)
延迟触发事件 Ajax异步请求数据 Jquery事件: Focus获得焦点 blur失去焦点 Change内容在变化的时候 Click点击事件 ---------------------------- ...