Skip to main content

Posts

Showing posts from January, 2020

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   {       ...