Yes, this is a simple DP problem:

#include <stdio.h>
#include <string.h>

#define MAX 100000

int main()
{
    int n, a[100], dp[100];
    while(scanf("%d", &n) == 1)
    {
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            dp[i] = MAX;
        }

        dp[n - 1] = 0;
        for(int i = n - 2; i > -1; i--)
            for(int j = i + 1; j < n && j - i <= a[i]; j++)
                if(dp[i] > dp[j] + 1) dp[i] = dp[j] + 1;

        if(dp[0] < MAX) printf("%d\n", dp[0]);
        else printf("Never!\n");

    }
    return 0;
}


On Fri, Jul 22, 2011 at 5:25 PM, sukhmeet singh <[email protected]>wrote:

> You are given an array with some values..traverse the array according to
> the rule that if a[i]=x then you can jump max up to x steps.. (if a[i]=0
> then you can't move any forward)
> find the least number of steps required to traverse the array ...
>
> EG:a[]=1 3 5 8 9 7 8 0 2 this requires 3 steps to traverse the array ..
> I think its DP .. but its just my intuition ..!!
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
from Yuchen Liao via Gmail
yyloves.me

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to