标签:
计数,排列Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
Hint
Description
Input
Output
Sample Input
2 3
Sample Output
1 2
解题思路:
这题主要讲的是一个错排公式
另:其实上式即错排公式 ,有关更多错排公式的性质及证明
需要注意的是,数组的定义与输出格式(结果可能会很大),代码中两种输出格式皆可以。
具体代码如下:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
long long a[21];
memset(a,0,sizeof(a));
a[0]=0;a[1]=0;a[2]=1;
for(int i=3;i<=20;i++)
{
a[i]=(i-1)*(a[i-2]+a[i-1]);
}
int n;
while (scanf("%d",&n)==1)
{
//printf("%lld\n",a[n]);
printf("%I64d\n",a[n]);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/llfj/p/5727292.html