<p>You are given an integer array <code>cost</code> where <code>cost[i]</code> is the cost of <code>i<sup>th</sup></code> step on a staircase. Once you pay the cost, you can either climb one or two steps.</p>

<p>You can either start from the step with index <code>0</code>, or the step with index <code>1</code>.</p>

<p>Return <em>the minimum cost to reach the top of the floor</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> cost = [10,<u>15</u>,20]
<strong>Output:</strong> 15
<strong>Explanation:</strong> You will start at index 1.
- Pay 15 and climb two steps to reach the top.
The total cost is 15.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> cost = [<u>1</u>,100,<u>1</u>,1,<u>1</u>,100,<u>1</u>,<u>1</u>,100,<u>1</u>]
<strong>Output:</strong> 6
<strong>Explanation:</strong> You will start at index 0.
- Pay 1 and climb two steps to reach index 2.
- Pay 1 and climb two steps to reach index 4.
- Pay 1 and climb two steps to reach index 6.
- Pay 1 and climb one step to reach index 7.
- Pay 1 and climb two steps to reach index 9.
- Pay 1 and climb one step to reach the top.
The total cost is 6.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= cost.length &lt;= 1000</code></li>
	<li><code>0 &lt;= cost[i] &lt;= 999</code></li>
</ul>

class Solution {
public:
     int solve(vector<int>cost,int count,int index){
       
        if(index==cost.size()-1){
            count+=cost[index];
            return count;
        }
        if(index>cost.size()-1){
            return count;
        }
         cout<<count<<" ";
        int ff=solve(cost,count+cost[index],index+1);
        int ss=solve(cost,count+cost[index],index+2);

        return min(ff,ss);
    }


    
    
    int solvemen(vector<int>cost,int count,int index,vector<int>dp){
       
        if(index==cost.size()-1){
            count+=cost[index];
            return count;
        }
        if(index>cost.size()-1){
            return count;
        }
         cout<<count<<" ";
         if(dp[index]!=-1)return dp[index];

        int ff=solvemen(cost,count+cost[index],index+1,dp);
        int ss=solvemen(cost,count+cost[index],index+2,dp);
        dp[index]=min(ff,ss);
        return dp[index];
    }
    int solve2(vector<int>& cost,int n,vector<int>dp){
        if(n<0){
            return 0;
        }
        if(n==0||n==1){
            return cost[n];
        }
        if(dp[n]!=-1)return dp[n];
        dp[n]= cost[n]+min(solve2(cost,n-1,dp),solve2(cost,n-2,dp));
        return dp[n];

    }
    int solve2tab(vector<int>cost){
        int n=cost.size();
        int *dp = new int[n];
        for(int i=0;i<n;i++){
            if(i<2){dp[i]=cost[i];}
            else {
                dp[i]=cost[i]+min(dp[i-1],dp[i-2]);
            }
            
        }
        return min(dp[n-1],dp[n-2]);
    }
    int solve1(vector<int>cost,int count,int target,int index){
        if(index==target){
            count+=cost[index];
            return count;
        }
        if(index<target){
            return count;
        }
        int ff=solve1(cost,count+cost[index],target,index-1);
        int ss=solve1(cost,count+cost[index],target,index-2);
        return min(ff,ss);
    }
    int minCostClimbingStairs(vector<int>& cost) {
        int n=cost.size();
        vector<int>dp(n,-1);
        // return min(solve2(cost,n-1,dp),solve2(cost,n-2,dp));
        return min(solve2tab(cost),solve2tab(cost));
    }
};
17400