#include<bits/stdc++.h>
using namespace std;
int limit = 10000000;
int dp[ 10000000 ] = {0};
int maximum = 0;
int solve( int n )
{
if( dp[n] != 0)
return dp[n];
if( n < 12)
return dp[ n ] = n;
else
return dp[ n ] = max(n, solve( n/2 ) + solve( n/3 ) + solve( n/4 ) );
}
int main()
{
int n;
{
cin>>n;
solve( n );
for(int i = 1; i <= limit; i++)
{
if( dp[i] > maximum )
maximum = dp[i];
}
cout<<endl<<maximum<<endl;
}
return 0;
}
http://www.codechef.com/viewsolution/6574636
Its is showing wrong answer, please help.
1 Like
use long long instead of int and ir should work fine… anyways this is my code if u need #include
using namespace std;
long long int arr[99999]={0};
long long int coin(long long int n)
{
if(n<12)
return n;
if(n<=99999){
if(arr[n]!=0)
return arr[n];}
long long int max1=max(n,coin(n/2)+coin(n/4)+coin(n/3));
if(n<=99999)
arr[n]=max1;
return max1;
}
int main()
{long long int n;
while(cin>>n,n!=0)
cout<<coin(n)<<endl;
}
Even your answer is showing WRONG ANSWER…I don’t understand why.
It seems yours and mine logic are same and correct.
http://www.codechef.com/viewsolution/6577345