Étiquettes » D.P.

Hackerrank : Davis' Staircase

/*
Code By : Pritish Thakkar
....DP !
....RECURSION !
*/
#include <bits/stdc++.h>
#define min_3(a,b,c) (min((a),min((b),(c))))
#define SET(a) memset(a,-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset(a,0,sizeof(a))
#define FILL(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define pi acos(-1.0)
#define inf 1000000007
#define ninf -1000000007
#define FOR(i,a,n) for(long long i=a;i<=n;i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n-1)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vv;
typedef vector<ii> vi;
typedef map<ll,vv> gg;
ll dp;
ll fun(ll n){
    if(n<1) return 0;
    if(n==1)
        return 1;
    else if(n==2)
        return  2;
    else if(n==3)
        return 4;
    else {
        if(dp[n] != 0) 
           return dp[n];
        return fun(n-1)+fun(n-2)+fun(n-3);
    }
}

int main() {
    CLR(dp);
    for(ll i=1;i<40;i++){
        dp[i] = fun(i);
    }
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cout<<fun(n)<<endl;
    }
    
    return 0;
}
Algorithm

Diler Honda Tabrak Aturan OJK

Jakarta, autokritik – Honda Surabaya Center (HSC), diler utama Honda di Jatim, Bali, dan NTT memberikan program penjualan menarik di pameran GIIAS Surabaya Auto Show 2016. 154 mots de plus

Mobil

Trust

Dilemma:

To trust again or

Not to trust?

Is it only a human condition?

Do I really need trust? Or can I live

My life without It? 14 mots de plus

Life

The Nine Virtues

Wisdom:

Wisdom begins in wonder. Socrates

Wisdom is best described as the ability to use your capacity for reasoning to come to a balanced and accurate assessment or judgement of a situation, person, or question.  144 mots de plus

ADF

337. House Robber III

The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the « root. » Besides the root, each house has one and only one parent house. 1 278 mots de plus

Need Review