求Fibonacci前K项和(0<K<41)
面向大海春暖花开
SGU 123 The sum
/************************************************************************* > File Name: sgu123.cpp > Author: Shine > Created Time: 2013-05-06 下午 6:05:51 > QuestionType: Water > Way: > Submit: > Gain: > Experience: ************************************************************************/ #include <cstdio> int re[50] = {0, 1, 2}; int f[50] = {0, 1, 1}; void predo() { int i; for (i = 3; i <= 45; i++) { f[i] = f[i-1] + f[i-2]; re[i] = re[i-1] + f[i]; } } int main() { predo(); int k; while (~scanf("%d", &k)) { printf("%d\n", re[k]); } return 0; }