9 degree subject 1122: eat candy, 9 degree subject 1122 candy

Source: Internet
Author: User

9 degree subject 1122: eat candy, 9 degree subject 1122 candy

Description:

The famous mother came back from a business trip and brought a box of delicious and exquisite chocolate to her name (N pieces of chocolate in the box, 20> N> 0 ).
Mom told her that she could eat one or two pieces of chocolate each day.
Suppose that the name eats chocolate every day, and ask how many different methods of eating chocolate are there.
For example:
If N = 1, the name will eat it in 1st days. There is one solution in total;
If N = 2, the name can be 1 in 1st days, 1 in 2nd days, or 2 in 1st days. There are two solutions in total;
If N = 3, the name can eat 1 item in 1st days, with 2 items left, or 2 items left in 1st days. Therefore, there are 2 + 1 = 3 naming schemes;
If N = 4, the name can be 1 item in 1st days, with 3 items left, or 2 items in 1st days, with 2 items left. There are 3 + 2 = 5 solutions.
Given N, please write a program to find the number of solutions for eating chocolate by name.

Input:

The input contains only one row, that is, integer N.

Output:

Multiple groups of test data may exist. For each group of data,
There is only one output line, that is, the number of plans for the name to eat chocolate.

Sample input:
4
Sample output:
5
The water question is relatively simple, and the code is directly used:
#include <stdio.h>long long computeNumber(int n){    if(n == 1 || n == 2) return n;    else {        return computeNumber(n - 1) + computeNumber(n - 2);    }}int main(){    int n;    long long total;    while(scanf("%d",&n) != EOF){        total = computeNumber(n);        printf("%lld\n",total);    }    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.