以下是来自spoj的问题的实现: - http://www.spoj.com/problems/COINS/
#include#define ll long long ll arr[100000]; ll max(ll n) { if(n < 49999)// Doubt { if(!arr[n]) return arr[n] = max(n/2) + max(n/3) + max(n/4); else return arr[n]; } else return max(n/2) + max(n/4) + max(n/3); } int main() { ll n, c = 0, i; for(i = 0; i < 12; i++) // Also why 12 when the input can be <12 { arr[i] = i; } while(scanf("%lld", &n) != EOF) { printf("%lld\n", max(n)); } return 0; }
为什么if条件包含n <49999?