摘要:
给定整数 a1, a2, a3, ..., an, 判断是否可以从中选出若干数,使他们的和恰好为k。1 <= n <= 20-10^8 <= ai <= 10^8-10^8 <= k <= 10^8int n, k, a[MAX_N];bool dfs(int i, int sum){ if(i == n) return sum == k; if(dfs(i+1, sum)) return true; if(dfs(i+1, sum + a[i])) return true; return false;}void solve(){ if(dfs(0,0)) 阅读全文
摘要:
利用记忆数组减少重复计算int memo[MAX_N+1];int Fbi(int i){ if(i 0) return memo[i]; return memo[i] = Fbi(i-1) + Fbi(i-2);} 阅读全文