c++ - Bytelandian gold coins wrong answer every time -
please me find why getting wrong answer bytelandian gold coins
question. here solution coins
#include <iostream> #include <cstdio> #include <map> #define max2(a, b) ((a) > (b) ? (a) : (b)) using namespace std; map <long long , long long > c; long long f(long long n) { if (n == 0) return 0; long long r = c[n]; if (r == 0) { r = max2( n , f(n/2)+f(n/3)+f(n/4) ); c[n] = r; } return r; } int main() { int t; long long n; scanf("%d",&t); while(t--){ scanf("%lld",&n); printf("%lld\n",f(n)); } return 0; }
i new dynamic programming,so google question , trying implement
spoj_coins,
still getting wrong answer on both codechef.com , spoj.
for problem, have take input until eof. taking input using test case.
try code:
#include <iostream> #include <cstdio> #include <map> #define max2(a, b) ((a) > (b) ? (a) : (b)) using namespace std; map <long long , long long > c; long long f(long long n) { if (n == 0) return 0; long long r = c[n]; if (r == 0) { r = max2( n , f(n/2)+f(n/3)+f(n/4) ); c[n] = r; } return r; } int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int t; long long n; { while(scanf("%lld",&n)==1) { printf("%lld\n",f(n)); } } return 0; }
Comments
Post a Comment