#include<bits/stdc++.h>
using namespace std;
int minimumjump(int a[], int n)
{
if(n == 1)
return 0;
int r = INT_MAX;
for(int i = n-2; i >= 0; i--)
{
if(i+a[i] >= n-1)
{
int sr = minimumjump(a, i+1);
if(sr != INT_MAX)
r = min(r, sr+1);
}
}
return r;
}
int main()
{
int n, i;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "\nEnter Each Array Value :: \n";
for(i=0;i<n;i++)
cin >> a[i];
int p = minimumjump(a, n);
cout << "\nMinimum Jump To Reach The Array End :: " << p << "\n";
return 0;
}
Comments
Post a Comment