第N个泰波那契数

题源:leetcode

链接:https://leetcode-cn.com/problems/n-th-tribonacci-number/

最简单的动态规划

 1 class Solution {
 2 public:
 3     int tribonacci(int n) {
 4         if(n==0) return 0;
 5         if(n==1) return 1;
 6         int a = 0;
 7         int b = 1;
 8         int c = 1;
 9         int d = 1;
10         for(int i = 2;i<n;i++){
11             d = a+b+c;
12             a = b;
13             b = c;
14             c = d;
15         }
16 
17         return d;
18     }
19 };
原文地址:https://www.cnblogs.com/hosheazhang/p/15084361.html