Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int house[105];
  4. int money[105];
  5. int ans[100];
  6. int check(int,int);
  7. int max(int,int,int);
  8. void save(int);
  9. int count=0;
  10. int main()
  11. {
  12. int n;
  13. scanf("%d",&n);
  14. for(int i=0;i<n;i++){
  15. scanf("%d",&house[i]);
  16. }
  17. check(n);
  18. if(money[n-2]>money[n-1]){
  19. printf("%d ",money[n-2]);
  20. }
  21. else printf("%d ",money[n-1]);
  22. return 0;
  23. }
  24. int check(int x){
  25. if(x==0||x==1){
  26. return house[x];
  27. }
  28. else{
  29. int s=check(x-1);
  30. int y=check(x-2)+house[x];
  31. int z=check(x-3)+house[x];
  32. return max(s,y,z);
  33. }
  34. }
  35. int max(int x,int y,int z){
  36. if(x>=y){
  37. if(x>=z) return x;
  38. else return z;
  39. }
  40. else{
  41. if(y>=z) return y;
  42. else return z;
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement