标签:class std pid code pre col turn pac div
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2046
思维:与之前有两道题目相似,n可以由n-1和n-2递推过来。f(n)=f(n-1)*1+f(n-2)*1.
也可以在草稿纸上直接画,寻找各项之间的规律。规律很明显。
code:
#include <iostream> using namespace std; int main() { int n; long long u[51]; while (cin >> n) { u[0] = 1; u[1] = 2; for (int i = 2; i < n; i++) u[i] = u[i - 1] + u[i - 2]; cout << u[n - 1] << endl; } return 0; }
标签:class std pid code pre col turn pac div
原文地址:https://www.cnblogs.com/CheeseIce/p/9738105.html