Skip steps (Getting Dynamic Programming)

Step jump

A staircase there are n steps, every time one or two may go, go ask the first steps from 0 n of steps a total of how many kinds of programs.

Input format
common line, comprising an integer n.

Output format
common line, contains an integer representing the number of programs.

Data range
1≤n≤15
Input Sample :
5
sample output:
8

Ideas:
The first step to level 0 only the first-stage table 1 Level A method steps
0th level to level 2, there are two methods one kind of steps 0-2 on Level 2 to Level 1 species is stepped on level 2 steps then the
0th step to level 3, there are two sets of one kind of methods is 0-2 2-31 species are then 0-11-3 (which already contains 0-11-22-3 in the foregoing method)

Program Number is a reverse view of the step number n = n-1 program number of the program steps of + n-2

#include <iostream>

using namespace std;

int arr[20];

int main()
{
    int n;
    cin >> n;
    arr[1] = 1; arr[2] = 2;
    for(int i = 3;i <=15;i++){
        arr[i] = arr[i-1]+arr[i-2];
    }
    cout << arr[n];

    return 0;

}
Released six original articles · won praise 0 · Views 90

Guess you like

Origin blog.csdn.net/zhongxinyun/article/details/104030128