Subdomain Posts
C | 3 days ago
C | 4 days ago
C | 5 days ago
C | 5 days ago
SQL | 5 days ago
C | 5 days ago
C | 6 days ago
C | 7 days ago
C | 7 days ago
C | 7 days ago
Recent Posts
None | 1 sec ago
None | 15 sec ago
None | 16 sec ago
None | 36 sec ago
None | 51 sec ago
Python | 57 sec ago
None | 1 min ago
None | 1 min ago
Power Shell | 1 min ago
None | 1 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 23rd of Jan 2010 03:40:10 PM Download | Raw | Embed | Report
  1. #include <iostream>
  2. #include <list>
  3.  
  4. using namespace std;
  5.  
  6. list<int> num_list;
  7.  
  8. void print_list()
  9. {
  10.     list<int>::iterator it;
  11.     bool is_first = true;
  12.     for(it = num_list.begin(); it != num_list.end(); it++)
  13.     {
  14.         if(!is_first)
  15.             cout << " + ";
  16.         else
  17.             is_first = false;
  18.         cout << *it;
  19.     }
  20.     cout << endl;
  21. }
  22.  
  23. void SumOptions_r(int sum, int cur_sum, int cur_num)
  24. {
  25.     if(sum == cur_sum)
  26.     {
  27.         print_list();
  28.         return;
  29.     }
  30.     int i;
  31.     for(i = cur_num; i>= 1; i--)
  32.     {
  33.         if(i + cur_sum > sum)
  34.             continue;
  35.         num_list.push_back(i);
  36.         SumOptions_r(sum, cur_sum + i, i);
  37.         num_list.pop_back();
  38.     }
  39. }
  40.  
  41. void SumOptions(int num)
  42. {
  43.     SumOptions_r(num, 0, num);
  44. }
  45.  
  46. void main()
  47. {
  48.     SumOptions(4);
  49.     getchar();
  50. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: