Topic 1122: Eating sweets

Source: Internet
Author: User

Title Description:

The name of the mother from the field back, with a box of delicious and beautiful chocolate to the name (the box has a total of n blocks of chocolate, > N >0).
Mom tells the name to eat one or two chocolates a day.
Let's say the name has chocolate every day, and how many different kinds of chocolate-eating programs are in the name.
For example:
If the n=1, then the name of the 1th day to eat it, a total of 1 options;
If n=2, then the name can eat 1 yuan on the 1th day, eat 1 yuan on the 2nd day, also can eat 2 pieces on 1th Day, a total of 2 kinds of programs;
If n=3, the name of the 1th day can eat 1 pieces, left 2 pieces, can also eat 1th Day 2 pieces left 1 pieces, so the name of a total of 2+1=3 species scheme;
If n=4, then the name can eat 1 yuan on the 1th day, the remaining 3, can also eat the 1th Day 2, left 2 pieces, a total of 3+2=5 species scheme.
Now given n, ask you to write a program to find out the number of famous chocolate-eating programs.

Input:

Input is only 1 lines, that is, integer n.

Output:

There may be multiple sets of test data, for each set of data,
The output is only 1 lines, that is, the number of programs that the name eats chocolate.

Sample input:
4
Sample output:
5
Source:

2008 the computer research of the graphics Laboratory of Peking University the real problem

#include <iostream>  //The problem is actually a Fibonacci sequence  112358......using namespace std;int f (int n) {    if (n==1)    {        return 1;    }    else if (n==2)    {        return 2;    }    else        return F (n-1) +f (n-2);} int main () {    int x;    while (cin>>x)    {        cout<<f (x) <<endl;    }    return 1;} /**************************************************************    problem:1122    User:carvin    language:c++    result:accepted    time:10 ms    memory:1520 kb******************************************* *********************/


Topic 1122: Eating sweets

Related Article

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.