2012年7月11日
摘要: 开始我的思路是:固定一半,另一半用组合公式cn1+cn2+cn3+cn4+.....+cni;最后用全排列减去它们即可。最后发现思路完全不对,必须用错排公式进行计算。即Cnm*a[N-m]; 从N个人中选出m个正确的,用错排公式算出(N-m)没在对应位置的个数。根据分步计数原理,可以得到结果。CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<math.h>usingnamespacestd;inta[21];doublePaC(intn,intm)//Permut 阅读全文
posted @ 2012-07-11 16:24 有间博客 阅读(798) 评论(0) 推荐(0) 编辑
摘要: CODE:#include<stdio.h>#include<stdlib.h>#include<string.h>#include<algorithm>usingnamespacestd;intn,u,d;intget_time(){inti;intx=u-d;intcur=0;for(i=1;i<=n/x;i++){cur=i*x;if(cur>=n-u&&cur<n)//还差一步到顶点{break;}}cur=2*i+1;//包括上升和下降的时间,所以乘以2returncur;}intmain(){whil 阅读全文
posted @ 2012-07-11 10:48 有间博客 阅读(148) 评论(0) 推荐(0) 编辑