/*摘自书本,这种算法很绕!*/
#include <iostream> using namespace std; int a[]={1,2,3,5}; int n=sizeof(a)/sizeof(int),k=12; 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; } int main() { if(dfs(0,0)) cout<<"yes"; else cout<<"no"; return 0; }