Coins - Bytelandian gold coins - Spoj


Coins - Bytelandian gold coins






Solution in C++


#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
#define pii pair<int,int>

lli n;
map<lli,lli> dp;

lli dp_it(lli x)
{
    if( (13*x)/12>x)return dp[x]=((dp[x/2])?dp[x/2]:dp_it(x/2))+((dp[x/4])?dp[x/4]:dp_it(x/4))+((dp[x/3])?dp[x/3]:dp_it(x/3));
    else return dp[x]=x;
}

int main()
{
 //   ios::sync_with_stdio(0);
 //   cin.tie(0);cout.tie(0);
    while(cin>>n)
        cout<<dp_it(n)<<"\n";
    return 0;
}

Share on Google Plus

About Mohamed Sobhi

My name is Mo.Sobhy ,I study at School excelling high school in Ain Shams ,Cairo
My hobbies is programming ,and web development ,playing chess and writing horror stories.
    Blogger Comment
    Facebook Comment

0 التعليقات:

إرسال تعليق