已知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的更多相关文章

  1. POJ 3088 斯特林

    题意:有一个n个按钮的锁,按下一些按钮打开门,有多少开门方式,其中,一些按钮可以选,可以不选,选中的按钮 可以分成一些集合,集合之间无序,是同时按下的. 分析: 1.首先选择 i 个按钮,组合数 2. ...

  2. 【noi 2.6_9283】&【poj 3088】Push Botton Lock(DP--排列组合 Stirling数)

    题意:N个编号为1~N的数,选任意个数分入任意个盒子内(盒子互不相同)的不同排列组合数. 解法:综合排列组合 Stirling(斯特林)数的知识进行DP.C[i][j]表示组合,从i个数中选j个数的方 ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  6. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

随机推荐

  1. java的classLoader原理理解和分析

    java的classLoader原理理解和分析 学习了:http://blog.csdn.net/tangkund3218/article/details/50088249 ClassNotFound ...

  2. Log4J日志配置具体解释

    一.Log4j简单介绍 Log4j有三个基本的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综 ...

  3. dns tunnel C&C

    通过DNS控制主机以及执行命令 我的ubuntu 安装过程 1854 mkdir dns_tunnel_tool 1855 cd dns_tunnel_tool/ 1856 ls 1857 git c ...

  4. 5. Longest Palindromic Substring[M]最长回文子串

    题目 Given a string s, find the longest palindromic substring in s. You may assume that the maximum le ...

  5. flask之jinji2模板介绍

    1.1.模板传参 (1)主程序   from flask import Flask,render_template app = Flask(__name__) @app.route('/') def ...

  6. H5自带进度条&滑块

    一.H5自带进度条 <div id="d1"> <p id="pgv">进度:0%</p> <progress id= ...

  7. SpringBoot(六) SpirngBoot与Mysql关系型数据库

    pom.xml文件的配置 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  8. const,var,let 区别

    js中const,var,let区别 1.const定义的变量不可以修改,而且必须初始化. 声明的是常量 1 const b = 2;//正确 2 // const b;//错误,必须初始化 3 co ...

  9. (转载)Android自定义标签列表控件LabelsView解析

    Android自定义标签列表控件LabelsView解析 作者 donkingliang 关注 2017.03.15 20:59* 字数 759 阅读 406评论 0喜欢 3 无论是在移动端的App, ...

  10. 多帧图片转gif

    示例 工具photosh cc2017 1: 文件--> 脚本--> 将文件载入堆栈--> 选择文件-->勾选窗口的时间轴-->底部 从图层建立帧--> 设置时间延 ...