Introduction

This is my blog of programming, I take notes and leave codes of computer science problems I solved here. Be my guest to comment :)
Showing posts with label Mathematic. Show all posts
Showing posts with label Mathematic. Show all posts

Thursday, December 6, 2012

uva 10616 - Divisible Group Sums


/*
Problem link
Type: DP, Mathematics
Algorithm:
 Let f(i,j,k) is the number of ways to choose i elements from a[1..j] so that
 their sum divides d gives the remainder of k. 

Tuesday, December 4, 2012

The Fibonacci Numbers


  • The rabbits growth problem:

Fibonacci's book Liber Abaci written in 1202 concerned about the growth of the number of rabbits in a certain area. The problem is: A young pair of rabbits, one of each sex, is placed on an island. Assuming that rabbits do not breed until they are two months old and after they are two months old, each pair of rabbits produces another pair each month, how many pairs are there after n months?

Let f(n) be the number of rabbits after n months. We have f(1) = 1 because only the original pair is on the island after one month. As this pair does not breed during the second month, f(2) = 1. To find the number of pairs after n months, add the number on the island the previous month, f(n-1), to the number of newborn pairs, which equals to f(n-2), because each newborn pair comes from a pair at least two months old. This leads to the following definition.


  • Definition: 

The Fibonacci sequence is defined recursively by f(1) = 1, f(2) = 1, and f(n) = f(n-1) + f(n-2) for n>=3. The terms of this sequence are called the Fibonacci Numbers

Tuesday, November 6, 2012

uva 406 - Prime Cuts

Types: Number theory, primes number, sieve...
Problem link
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
using namespace std;
const int maxn = 1010;
//------------------------------------
int a[maxn];
bool isPrime[maxn];
int n,c;

Friday, October 26, 2012

Codeforces round #147 div 2 - Problem C


/*
This program solve Problem C codeforces round #147 div 2
Date: 26/10/2012
  -------------------------------
*/
#include <iostream>
#include <cstdio>
#include <cstring>