//http://www.spoj.com/problems/COINS/
#include <iostream>
#include <cstdlib>
using namespace std;
#define MEMOSIZE 1000000
unsigned 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;
}
Bytelandian gold coins
最新推荐文章于 2018-11-20 20:16:45 发布