错排递推公式:

d(n) = (n-1)*(d[n-1]+d[n-2]);

证明:将第n个元素放到第k处,第k处的元素如果放到第n处,就是d(n-2),否则,先假设放到第n处,然后错排,就是d(n-1);

 #include <bits/stdc++.h>

 using namespace std;

 double fac[] = {,};
double d[] = {,,,}; int main()
{
for(int i=;i<;i++)
fac[i] = i*fac[i-]; for(int i=;i<;i++)
d[i] = (i-)*(d[i-]+d[i-]); int c;
scanf("%d",&c);
while(c--) {
int n;
scanf("%d",&n);
printf("%.2f%c\n",d[n]*/fac[n],'%');
} return ;
}

最新文章

  1. lightBox灯箱效果
  2. 81B
  3. Django web 基础
  4. Android周笔记(9.8-14)(持续更新)
  5. Oracle中的Union、Union&#160;All、Intersect、Minus
  6. 规划(纪念我在ACM道路上的一年)
  7. shell命令一行代码搞定【转】
  8. (转) qt: usb热插拔(linux);
  9. python 基础之注释变量常量
  10. bzoj2560串珠子(子集dp)
  11. TextArea 保存时换行符处理
  12. struts2框架之拦截器(参考第二天学习笔记)
  13. js获取过滤条件中参数的快捷方式
  14. Vue router 的使用--初级
  15. [个人项目] 使用 Vuejs 完成的音乐播放器
  16. APP测试体系
  17. MongoDB(课时22 过期索引)
  18. 趣味编程:24点(Haskell版)
  19. JSP学习(四)JSP属性范围
  20. [GO]结构体指针变量初始化

热门文章

  1. git push的一些坑
  2. DbUtils(二) 结果集实例
  3. 求入栈顺序为1234……N的序列的所有可能的出栈序列
  4. The Definitive C++ Book Guide and List--reference
  5. C语言中extern的用法--转
  6. js 标签属性与导航
  7. 【shell】《shell学习指南》读书笔记
  8. 2、Angular2 Directive
  9. glyphicons-halflings-regular.woff2 文件 404
  10. Java集合篇一:ArrayList