fork download
  1. #include <vector>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int main(void){
  8. int n=30;
  9. vector<int> possible_answers({0,4,7,10});
  10. int max_answer = n * *(max_element(possible_answers.begin(),possible_answers.end()));
  11. vector<bool> reachable(max_answer,false);
  12. reachable[0] = true;
  13. for (int i=0;i<n;++i){
  14. vector<bool> reachable_next(reachable);
  15. for (int j=0;j<max_answer;++j){
  16. if (reachable[j]) {
  17. for (int k : possible_answers){
  18. if(j+k<max_answer){
  19. reachable_next[j+k] = true;
  20. }
  21. }
  22. }
  23. }
  24. reachable=reachable_next;
  25. }
  26. for (int i=0;i<max_answer;++i){
  27. if(!reachable[i]){
  28. cout<<i<<'\n';
  29. }
  30. }
  31.  
  32. }
Success #stdin #stdout 0s 3028KB
stdin
Standard input is empty
stdout
1
2
3
5
6
9
13
283
286
289
292
293
295
296
298
299