You are not logged in. Please login at www.codechef.com to post your questions!

×

COINS: Getting rte

#include<iostream>
#include<cmath>
#include<vector>
using namespace std;

int max(int a,int b)
{
    if(a>b) return a;
    else return b;
}

int f(int n,int val[])
{
    int a,b,c,d;

    if(n==0){val[n]=0; return val[n];}
    else if(n==1){val[n]=1; return val[n];}
    else if(n==2){val[n]=2; return val[n];}
  else if(val[n]!=0) {return val[n];}
  else  {b=f(n/2,val);
         c=f(n/3,val);
         d=f(n/4,val);
         a= max(n,b+c+d);
         val[n]=a;
         return a;}
         }

main()
{
      int n,ab;
      int val[10000]={0};
      while(cin>>n) {ab=f(n,val);cout<<ab<<endl;}
     // cout<<f(12)<<endl;

      }

Problem??

asked 31 Mar '12, 01:42

cstdio's gravatar image

2★cstdio
1115
accept rate: 0%

edited 10 Jul '12, 13:31

admin's gravatar image

0★admin ♦♦
19.8k350498541

Please format your code properly and post.

Yes problem, your code is UNREADABLE

(04 Apr '12, 01:53) abhimanyuma3★

Please look at the limits : 0 <= n <= 1 000 000 000

Your solution is made for 0 <=n <= 10 000

Memory will overflow giving SIGSEGV

link

answered 04 Apr '12, 01:59

abhimanyuma's gravatar image

3★abhimanyuma
19133
accept rate: 100%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×525
×231
×65
×55

question asked: 31 Mar '12, 01:42

question was seen: 1,313 times

last updated: 10 Jul '12, 13:31