question Description
| 800603 Eat Sweets /td> |
| |
| 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 pieces of chocolate). 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 N=1, then the name of the 1th day to eat it, a total of 1 kinds of programs; if n=2, then the first name can eat the 1th day of 1, the 2nd day to eat 1, can also be 1th day to eat 2 pieces, a total of 2 programs; if n=3, then the name 1th Day can eat 1 pieces, 2 blocks left, can also 1th 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, 3 pieces left, you can also eat the 1th Day 2, 2 pieces left, a total of 3+2=5 schemes. Now given n, ask you to write a program to find out the number of famous chocolate-eating programs. |
| input |
| Enter only 1 rows, or integer n. |
| output |
| output is only 1 lines, that is, the number of programs that the name eats chocolate. |
| Input Example |
| 4 |
| Output Example /td> |
| 5 |
| Other instructions |
| data range: 0 <n<20. |
Puzzle: Fibonacci??
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn= -+5; One intF[MAXN]; A intdpintN) { - if(F[n])returnF[n]; - if(!n| | n==1)return 1; the if(n==2)return 2; - returnDP (n1) +DP (n2); - } -InlineintRead () { + intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; + for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; A returnsig?x:-x; at } -InlinevoidWriteintx) { - if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; - for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; - } in voidinit () { - intn=read (); to Write (DP (n)); + return; - } the voidWork () { * return; $ }Panax Notoginseng voidprint () { - return; the } + intMain () {init (); work ();p rint ();return 0;}
Coj 0584 800603 Eating sweets