From a897696e7f70595b4be6c4c82cdd71288292a1bd Mon Sep 17 00:00:00 2001 From: JohnnyQuintero16 Date: Thu, 14 Oct 2021 23:09:18 -0500 Subject: [PATCH] add exercise tribonacci --- C++/Language/tribonacci.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 C++/Language/tribonacci.cpp diff --git a/C++/Language/tribonacci.cpp b/C++/Language/tribonacci.cpp new file mode 100644 index 0000000..c05feef --- /dev/null +++ b/C++/Language/tribonacci.cpp @@ -0,0 +1,31 @@ +/* + Author : Johnny Quintero + Date : Date format 14/10/2021 + Description : C++ program to calculate the tribonacci of a number with programming dynamic +*/ + #include + using namespace std; + #define ll long long + const ll MOD = 1000000007; + ll dp[100000+1]; // table of memorization of answers + + //Function to calculate the tribonacci with programming dynamic + void tribonaci(){ + dp[1] = 0; + dp[2] = 0; + dp[3] = 1; + for(int i = 4; i <= 100000; i++){ + dp[i] = ( dp[i-1]%MOD + dp[i-2]%MOD + dp[i-3]%MOD ) %MOD; + } + } + + + int main() { + // initialize the memorization table to zero + memset(dp,0,sizeof(dp)); + tribonaci(); + ll n; + while(cin>>n){ + cout<< dp[n] <