递推题,虽然做出来了,但又走了弯路
mycode:
实际上:f(n) = f(n-1)+f(n-2).
#include <iostream> using namespace std; int main() { long long n,ans[51]; ans[1]= 1;ans[2] = 2;ans[3] = 3; for(int i = 4 ;i < 51;i ++) ans[i] = ans[3] * ans[i-3] + ans[i-2] * ans[2] + ans[i-1]*ans[1] - 1*ans[i-2] - 2*ans[i-3] - 1*ans[i-3]; while(cin >> n) cout << ans[n] << endl; return 0;}
时间: 2024-10-14 06:54:03