1 条题解

  • 0
    @ 2024-12-24 9:49:24

    C :

    #include <stdio.h>
    long long fun(int x)
    {
    	if(x==1)
    	return 0;
    	if(x==2)
    	return 1;
    	else
    	return ((x-1)*(fun(x-2)+fun(x-1)));
    }
    int main()
    {
    	int n;
    	while(scanf("%d",&n)!=EOF)
    	{
    		printf("%lld\n",fun(n));
    	}
    	return 0;
    }
    
    

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    #define maxn 100000007
    int main()
    {
    	int d[1005];
    	d[2]=1;d[1]=0;
    	for (int i=3;i<999;i++){
    		d[i]=(i-1)*(d[i-1]+d[i-2])%maxn;
    	}
    	
    	int n;
    	while(~scanf("%d",&n)){
    		printf("%d\n",d[n]);
    	}
    	
    	return 0;
    }
    
    • 1

    信息

    ID
    877
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者