集训第六周 数学概念与方法 计数 排列 L题

Description

大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 
做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。 
话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。

不幸的是,这种小概率事件又发生了,而且就在我们身边: 
事情是这样的――HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!

现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?

Input

输入数据包含多个多个测试实例,每个测试实例占用一行,每行包含一个正整数n(1<n<=20),n表示8006的网友的人数。

Output

对于每行输入请输出可能的错误方式的数量,每个实例的输出占用一行。

Sample Input

2
3

Sample Output

1
2

可以使用著名的错排公式,

M(n)=(n-1)[M(n-2)+M(n-1)]

特殊地,M(1)=0,M(2)=1

#include"stdio.h"
int main()
{
    long long ans[21];
    ans[1]=0;ans[2]=1;
    for(int i=3;i<=20;i++)
    ans[i]=(i-1)*(ans[i-1]+ans[i-2]);
    int n;
    while(scanf("%d",&n)!=EOF)  printf("%I64d\n",ans[n]);
    return 0;
}

时间: 2024-08-26 13:01:56

集训第六周 数学概念与方法 计数 排列 L题的相关文章

集训第六周 数学概念与方法 数论 线性方程 I题

Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Trees Trees are Shaking, Leaves are Falling. Lovers Walk passing, and so are You. ................................Write in English class by yifenfei Gir

集训第六周 数学概念与方法 数论 筛素数 G题

Description 小明对数的研究比较热爱,一谈到数,脑子里就涌现出好多数的问题,今天,小明想考考你对素数的认识.  问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数.  给定一个区间,你能计算出这个区间内有多少个美素数吗? Input 第一行输入一个正整数T,表示总共有T组数据(T <= 10000). 接下来共T行,每行输入两个整数L,R(1<= L <= R <= 10

集训第六周 数学概念与方法 概率 F题

Submit Status Description Sometimes some mathematical results are hard to believe. One of the common problems is the birthday paradox. Suppose you are in a party where there are 23 people including you. What is the probability that at least two peopl

集训第六周 数学概念与方法 概率 数论 最大公约数 G题

Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must hide in one of the holes. A wolf searches the rabbit in anticlockwise order. The first hole he get into is the one signed with 0. Then he will get into

集训第六周 数学概念与方法 UVA 11181 条件概率

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概率会给出,问这一群人去买东西,第i个人属于r之中的概率是多少 思路:首先得了解什么是条件概率. 条件概率:事件A在事件B成立的基础上再成立的概率,公式为:P(A|B)=P(A*B)/P(B) 可以照着题目案例1进行分析: 输入 0.10 0.20 0.30 输出 0.413043 0.739130

集训第六周 数学概念与方法 UVA 11722 几何概型

---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[s1,s2]的时间段停留在同一个站点w分钟,问两辆火车能够在这个站点相遇的概率. 思路,枚举每一种情况,把两辆火车的相交区间画出来,然后求都在这个区间的概率 #include"iostream" #include"cstdio" #include"cmath&

集训第六周 数学概念与方法 概率 N题

N - 概率 Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (he wants everything quick!) so he decided to rob banks.

集训第六周 古典概型 期望 D题 Discovering Gold 期望

Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold. Initially you are in position 1. Now each turn you throw a perfect 6 sided dice. If you get X in the dice a

集训第六周 E题

E - 期望(经典问题) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once.