Dynamic Planning DP ---- PPT

Source: Internet
Author: User

 

 

#include <stdio.h>int fib(int n){if(n<=1) return 1;else return fib(n-1)+fib(n-2);}int main( ){int n;scanf("%d",&n);printf("%d\n" ,fib(n) );}
View code

 

 

#include <stdio.h>int fib(int n){    if(n<=1)     return 1;    else         return fib(n-1)+fib(n-2);}int main( ){    int n;    while(scanf("%d",&n))    printf("%d\n" ,fib(n) );}
View code

 

 

 

 

 

 

230 = (210) 3 = 109

 

240 = (210) 4 === 1012 250 === 1015

 

 

The 10th power of 2 is 1024
The 46 power of 2 is the 5 power of 1024 divided by the 4 power of 2 = 70368744177664.00 ======= 1013

 

 

 

 

 

 

 

 

 

 

 

 

 

 

#include <stdio.h>#define MAX 50+1int a[MAX];int fib(int n){     if (a[n]==-1)          return a[n]=fib(n-1)+fib(n-2);     else  return  a[n];  }int main( ){    int i,n;    for(i=1; i<MAX; i++)    a[i]=-1;         a[0]=a[1]=1;    scanf("%d",&n);   printf("%d\n" ,fib( n ) );}
View code

 

 

# Include <stdio. h>

# Define Max 50 + 1

Int A [Max];

Int fib (int n)

{If(A [n] =-1)Return A [n] = fib (n-1) + fib (n-2); // IfA [n] =-1, not counted

Else return a [n];

}

 

Int main ()

{

Int I, N;

For (I = 1; I <Max; I ++) A [I] =-1;// Mark, and the initial values of all elements-1

A [0] = A [1] = 1 ;//Value assignment, initialization, known condition

Scanf ("% d", & N );

Printf ("% d \ n", FIB (n ));}

 

 

 

 

 

 

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.