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