int DP_ABString(int count) { int fa[1000], fb[1000]; if(count > 1000) return -1; memset(fa, 0, sizeof(fa)); memset(fb, 0, sizeof(fb)); for(int i.

Slides:



Advertisements
Similar presentations
Exemplos. Algoritmos – bisseção TolFun = eps; fa = feval(f,a); fb = feval(f,b); if fa*fb > 0, error ('Devemos ter f(a)*f(b)
Advertisements

For(int i = 1; i
Counting Andreas Klappenecker. Counting k = 0; for(int i=1; i
void count_down (int count) { for(i=count; i>1; i--) printf(" %d\t", count); } printf("A%d\n", count); if(count>1) count_down(count-1); printf("B%d\n",
Functions Prototypes, parameter passing, return values, activation frams.
Divisor máximo de dois inteiros. unsigned int gcd(unsigned int A, unsigned int B) { if (B > A) return gcd(B,A); else if (B==0) return A; else return gcd(B,A%B);}
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
EC-241 Object-Oriented Programming
Queues What is a queue? Queue Implementations: –As Array –As Circular Array –As Linked List Applications of Queues. Priority queues.
Computer Science A 7: 27/2. Methods - subroutines Chapter 4 static return-type name ( parameters ) { statements } Call a method name ();
Recursion. Idea: Some problems can be broken down into smaller versions of the same problem Example: n! 1*2*3*…*(n-1)*n n*factorial of (n-1)
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
June 18, 2015IAT 2651 Recursion. June 18, 2015IAT 2652 Today’s Excitement  Recursion.
Data Structures Using C++1 Chapter 6 Recursion. Data Structures Using C++2 Chapter Objectives Learn about recursive definitions Explore the base case.
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.
Problem Set 5: Problem 2 22C:021 Computer Science Data Structures.
Class Opener:. Identifying a Composite Function:
STARTING OUT WITH STARTING OUT WITH Class 3 Honors.
 2007 Pearson Education, Inc. All rights reserved Random Number Generation  rand function – Load – Returns "random" number between
Public class Edo1 { private static double euler(double y, double h, double t, Derivada d) { return y + h * d.f(y, t); } public static void euler(double.
Compiling a Native C++ Program on the Command Line #define #include.
/** * Write a description of class Board here. * Khalid (a version number or a date) */ /** Pawel Durakiewicz 10/19/12.
/* example program to demonstrate the passing of an array */ #include int maximum( int [] ); /* ANSI function prototype */ int maximum(
 Head pointer  Last node  Build a complete linked list  Node deletion  Node insertion  Helpful hints.
Revision on C++ Pointers TCP1201: 2013/2014. Pointer Basics  Why pointer is important? 1. Reference/Point to existing data without cloning the data.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
for( 起始條件 ; 判斷式 ; 條件運算 ){ // 迴圈內容 } while( 判斷式 ){ // 迴圈內容 } do{ // 迴圈內容 } while( 判斷式 ) ;
Recursive. Recursive F(n) = F(n-1) + F(n-2) n! = (n-1)! x n C(m,n) = C(m-1,n-1)+C(m-1,n)......
Copyright © 2012 Pearson Education, Inc. 16/4/1435 h Sunday Lecture 3 1.Using a Loop to Step Through an array 2.Implicit Array Sizing 3.No Bounds Checking.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Looping Examples I.
3.2 Rolle’s Theorem and the
Queues.
Two Dimensional Arrays
IAT 800 Recursion Oct 28, 2009 IAT 800.
IAT 265 Recursion May 24, 2016 IAT 265.
Queues What is a queue? Queue Implementations: As Array
עקרנות תכנות מונחה עצמים
Rolle’s Theorem.
Random Number Generation
3.2 Rolle’s Theorem and the
Functions: Declaration, Definition, Call and return, Scope of variables, Storage classes, Recursive functions, Recursion vs Iteration.
Average Rate vs. Instantaneous Rate
CS 153 Design of Operating Systems Winter 2016
1020: Introduction to Programming Mohamed Shehata December 1, 2017
Multidimensional Arrays
  30 A 30 B 30 C 30 D 30 E 77 TOTALS ORIGINAL COUNT CURRENT COUNT
TicTacToe 過三關 使用者可按 XO X char gb[3][3]; gb[0][1] gb[0][0] gb[0][2]
Assignment Operators Topics Increment and Decrement Operators
CS1201: Programming Language 2
Average Rate vs. Instantaneous Rate
Average Rate vs. Instantaneous Rate
Example 1 Ask the user to type10 integers of an array T1 and 10 integers of an array T2. Put into T3, an array with 20 integers : the sum of the elements.
Count on 2 (Over the bridge)
Main() { int fact; fact = Factorial(4); } main fact.
Intermediate Value Theorem
Assignment Operators Topics Increment and Decrement Operators
Assignment Operators Topics Increment and Decrement Operators
Counting to 100 Counting by ones
Programming Arrays.
How Memory Leaks Work with Memory Diagram
CISC 110 Day 3 Programming Review.
Assignment Operators Topics Increment and Decrement Operators
Queues What is a queue? Queue Implementations: As Array
Scope Rules.
Presentation transcript:

int DP_ABString(int count) { int fa[1000], fb[1000]; if(count > 1000) return -1; memset(fa, 0, sizeof(fa)); memset(fb, 0, sizeof(fb)); for(int i = 1; i < count; i++) fa[i] = fa[i-1] + fb[i-1]; fb[i] = fb[i-1] + fa[i-1] + i%2; } return fb[count-1];

int DP_Domino(int n) { int d[1000][3]; if(n%2) return -1; d[1][0] = d[1][2] = 1; d[0][0] = d[1][1] = d[0][2] = 1; for(int i = 2; i <= n; i++) d[i][0] = d[i-2][0] + d[i-1][1] + d[i-2][2]; d[i][1] = d[i-1][2]; d[i][2] = d[i][0] + d[i-1][1]; } return d[n][0];