Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. public int countWays(int n) {
  2. if (n < 0)
  3. return 0;
  4. else if (n == 0)
  5. return 1;
  6. else {
  7. return countWays(n-1) + countWays(n-2) + countWays(n-3);
  8. }
  9. }
  10.  
  11. countWays(4)
  12.  
  13. (3,1), (1,3)
  14. (2,1,1), (1,2,1), (1,1,2)
  15. (1,1,1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement