LightOJ 1006 Hex-a-bonacci Solution

 







Solve in C++:
///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
#define mx 100009
#define mod 10000007
ll dp[mx],t,n,a,b,c,d,e,f;
ll fn(ll n)
{
    if (n == 0return a;
    if (n == 1return b;
    if (n == 2return c;
    if (n == 3return d;
    if (n == 4return e;
    if (n == 5return f;
    if(dp[n]!=-1)return dp[n];
    else
    {
        dp[n]=(fn(n-1) + fn(n-2) + fn(n-3) + fn(n-4) + fn(n-5) + fn(n-6))%mod;
        return dp[n];
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll i=1;
    cin>>t;
    while(t--)
    {
        memset(dp,-1,sizeof(dp));
        cin>>a>>b>>c>>d>>e>>f>>n;
        printf("Case %lld: %lld\n",i++,fn(n)%mod);

    }
}



No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.