CCF NOI100003 up the stairs __noi100003

Source: Internet
Author: User

question link : CCF NOI100003 up the stairs .


Time limit: 1000 ms Space limit: 262144 KB

Topic Description

Stairs have n steps, stairs can be a step up the stairs, can also step two steps. Compile a program to calculate how many different walks are in total.

input

One row, an integer n (1 <= n <= 30), represents the series of steps .

Output

An integer, the number of methods to go.

Sample Input

3
Sample Output

3
Programme 1: Walk three times, one step at a time
Scenario 2: Go first, then two.
Option 3: Go to Level Two first, go again

Data Range Restrictions




Problem Analysis

This is a recursive computation problem, the key is to find the recursive type.

See the reference link.

Program Description

Slightly

Essentials to use functions to encapsulate functional functions as far as possible. The key to recursion problem is recursion type.


Reference link : HDU2041 super Staircase.

The C language Program of 100 minutes:

#include <stdio.h>

typedef unsigned long long ull;

ull Stairs (int n)
{
    ull f1=1, f2=2, temp;

    if (n = = 0) return
        0;
    else if (n = = 1) return
        1;
    else if (n = = 2) return
        2;

    for (int i=3; i<=n; i++) {
        temp = f1 + F2;
        f1 = F2;
        F2 = temp;
    }

    return f2;
}

int main (void)
{
    int n;

    scanf ("%d", &n);

    printf ("%lld\n", Stairs (n));

    return 0;
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.