Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions C++/Language/tribonacci.cpp
Original file line number Diff line number Diff line change
@@ -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 <bits/stdc++.h>
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] <<endl;
}
}