Skip to main content

Posts

Resources for Programming Contest

Some important resources:                                           BAPS-BACS 1.CPPS                                                           7.Problem Solving Strategies 2.Beginner to Expert                                     8.An Awesome Blog for Programming 3.Bangla Resources                                      9.Ahnaf's Bangla Blog 4.Collection of Shakkhar                              10. Collection of UpsideDown ...

Light OJ-1085

Problem No-  1085 (All Possible Increasing Subsequences ) This is an interesting data structure based problem.It can be solved by  segment tree  or  Binary Index Tree(BIT) . Here numbers can be both negative and positive. If we want to solve with BIT then we need to  compressed the array. After that we can easily solve this problem using BIT. Here is the solution (BIT)- My Solution

Light OJ - 1095

Problem No: 1095 - Arrange the Numbers This problem has two parts. This is a typical combinatorics problem. #include<bits/stdc++.h> using   namespace  std ; #define ll long long #define mod 1000000007 #define N 1000 ll ncr [ N  +   2 ] [ N  +   2 ] ; ll fact [ N  +   2 ] ; int  main ( ) {     ncr [ 0 ] [ 0 ]   =   1 ;      for   ( int  i  =   1 ;  i  <=  N ;  i ++ )   {          for   ( int  j  =   0 ;  j  <=  N ;  j ++ )   {              if   ( j  >  i )  ncr [ i ] [ j ]   =   0 ;              else   if   ( j  ==   0   ||  i  ==  j )  ncr [ i ] [ j ]   =   1 ; ...

Light OJ 1326 - Race

Problem No: 1326-Race Both combinatorics and dynamic problem concept is used in this problem. We calculate how many ways the race can finish. #include<bits/stdc++.h> using   namespace  std ; #define ll long long #define N 1000 #define mod 10056 ll ncr [ N  +   1 ] [ N  +   1 ] ; ll dp [ N  +   1 ] ; int  main ( ) {     ll xx, yy ;      int  i, j ;     ncr [ 0 ] [ 0 ]   =   1 ;      for   ( i  =   1 ;  i  <=  N ;  i ++ )   {          for   ( j  =   0 ;  j  <=  N ;  j ++ )   {              if   ( j  >  i )  ncr [ i ] [ j ]   =   0 ;              else   if   ( j  ==  i  ...

Light OJ 1110 - An Easy LCS

LCS:   An Easy LCS This is an interesting LCS dp for problem for beginner. There is many solution for this problem. In problem this firstly we calculate the size of LCS using recursively. string A, B ; int  n, m ; int  dp [ 102 ] [ 102 ] ; int  lcs ( int  i,  int  j ) {      if   ( i  ==  n  +   1   ||  j  ==  m  +   1 )   {          return   0 ;      }      if   ( dp [ i ] [ j ]   ! =   - 1 )   return  dp [ i ] [ j ] ;      int  x  =   0 ;      if   ( A [ i ]   ==  B [ j ] )   {         x  =  lcs ( i  +   1 , j  +   1 )   +   1 ;      }      else   {       ...

Hashing

Hashing is an very interesting topic in competitive programming.Using memory we can efficient our program and that's called Hashing. We are talking about string processing using Hashing.   Hash Function : The concept of number system is used for hash function. Suppose, you are given 5, 2 ,5, 2 and asked to make it 5252. You can easily do it.                                                                 0 * 10 + 5      =  5           H[1] = 5                                                                 1 * 10 + 2      =  52         H[2] = 52       ...