LightOJ 1006 Hex-a-bonacci Solution
Problem Link: https://lightoj.com/problem/hex-a-bonacci
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 == 0) return a;
if (n == 1) return b;
if (n == 2) return c;
if (n == 3) return d;
if (n == 4) return e;
if (n == 5) return 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