fufuQAQ @ 2022-03-01 23:40:50
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5010;
int f[N];//记录次数
int fac(int n)
{
if(n==1||n==2) return f[n]=1;
if(f[n]!=0) return f[n];
// return fac(n-1)+fac(n-2);
else return f[n]=fac(n-1)+fac(n-2);
}
int main()
{
int n;
cin>>n;
cout<<fac(n);
return 0;
}
by AC_CSP @ 2022-03-02 07:35:04
else return f[n]=fac(n-1)+fac(n-2)
这里后面这个表达式为1啊,应该分两步写
f[n]=fac(n-1)+fac(n-2); return f[n];
by Beyond_Heaven @ 2022-03-02 08:38:42
@AC_CSP 你在说__,学下C++罢
by Beyond_Heaven @ 2022-03-02 08:39:35
@zhejianguniversity 这题需要python
by AC_CSP @ 2022-03-02 09:34:59
@Beyond_Heaven
跟python有啥关系?赋值语句默认返回1
by AC_CSP @ 2022-03-02 09:36:38
主要是高精,我的意思是算法...
by AC_CSP @ 2022-03-02 09:37:23
@Beyond_Heaven
by YuzhenQin @ 2022-03-02 09:47:55
@AC_CSP 可以这么写吧
by YuzhenQin @ 2022-03-02 09:52:36
@AC_CSP Assignment Operators
All built-in assignment operators return this, and most user-defined overloads also return this so that the user-defined operators can be used in the same manner as the built-ins. However, in a user-defined operator overload, any type can be used as return type (including void).
by Beyond_Heaven @ 2022-03-02 09:53:19
@AC_CSP 这边请问一下平时有使用电脑编程的习惯吗
by Retired_lvmao @ 2022-03-02 09:55:30
@AC_CSP
你是不是没见过 printf("%d\n",lastans=ans)
之类的写法。