Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int house[105];
- int money[105];
- int ans[100];
- int check(int,int);
- int max(int,int,int);
- void save(int);
- int count=0;
- int main()
- {
- int n;
- scanf("%d",&n);
- for(int i=0;i<n;i++){
- scanf("%d",&house[i]);
- }
- check(n);
- if(money[n-2]>money[n-1]){
- printf("%d ",money[n-2]);
- }
- else printf("%d ",money[n-1]);
- return 0;
- }
- int check(int x){
- if(x==0||x==1){
- return house[x];
- }
- else{
- int s=check(x-1);
- int y=check(x-2)+house[x];
- int z=check(x-3)+house[x];
- return max(s,y,z);
- }
- }
- int max(int x,int y,int z){
- if(x>=y){
- if(x>=z) return x;
- else return z;
- }
- else{
- if(y>=z) return y;
- else return z;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement