Bytelandian gold coins

来源:互联网 发布:三大耻辱 知乎 编辑:程序博客网 时间:2024/06/17 06:54
//http://www.spoj.com/problems/COINS/#include <iostream>#include <cstdlib>using namespace std;#define MEMOSIZE 1000000unsigned memo[MEMOSIZE];unsigned maxprofit(unsigned n) {unsigned s;if ((n<MEMOSIZE)&&memo[n]) return memo[n]-1;s=maxprofit(n/2)+maxprofit(n/3)+maxprofit(n/4);s=(s>n)?s:n;if(n<MEMOSIZE) memo[n]=s+1;return s;}int main(int argc, char* argv[]) {unsigned n;for(n=0; n<12; n++) memo[n]=n+1;while(scanf("%u", &n)==1) cout << maxprofit(n) << endl;}

0 0