codeparrot/xlcost-text-to-code huggingface dataset:
Number of ways to split N as sum of K numbers from the given range | C # implementation to count the number of ways to divide N in K groups such that each group has elements in range [ L , R ] ; DP Table ; Function to count the number of ways to divide the number N in K groups such that each group has number of elements in range [ L , R ] ; Base Case ; If N is divides completely into less than k groups ; If the subproblem has been solved , use the value ; Put all possible values greater equal to prev ; Function to count the number of ways to divide the number N ; Initialize DP Table as - 1 ; Driver Code
using System ; class GFG { static int mod = 1000000007 ; static int [ , ] dp = new int [ 1000 , 1000 ] ; static int calculate ( int pos , int left , int k , int L , int R ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; if ( dp [ pos , left ] != - 1 ) return dp [ pos , left ] ; int answer = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( i > left ) break ; answer = ( answer + calculate ( pos + 1 , left - i , k , L , R ) ) % mod ; } return dp [ pos , left ] = answer ; } static int countWaystoDivide ( int n , int k , int L , int R ) { for ( int i = 0 ; i < 1000 ; i ++ ) { for ( int j = 0 ; j < 1000 ; j ++ ) { dp [ i , j ] = - 1 ; } } return calculate ( 0 , n , k , L , R ) ; } public static void Main ( ) { int N = 12 ; int K = 3 ; int L = 1 ; int R = 5 ; Console . Write ( countWaystoDivide ( N , K , L , R ) ) ; } }
Minimum number of squares whose sum equals to given number N | set 2 | C # program to represent N as the sum of minimum square numbers . ; Function for finding minimum square numbers ; A [ i ] of array arr store minimum count of square number to get i ; sqrNum [ i ] store last square number to get i ; Initialize ; Find minimum count of square number for all value 1 to n ; In worst case it will be arr [ i - 1 ] + 1 we use all combination of a [ i - 1 ] and add 1 ; Check for all square number less or equal to i ; if it gives less count then update it ; List v stores optimum square number whose sum give N ; Driver code ; Calling function ; Printing vector
using System ; using System . Collections . Generic ; class GFG { static List < int > minSqrNum ( int n ) { int [ ] arr = new int [ n + 1 ] ; int k = 0 ; int [ ] sqrNum = new int [ n + 1 ] ; List < int > v = new List < int > ( ) ; arr [ 0 ] = 0 ; sqrNum [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { arr [ i ] = arr [ i - 1 ] + 1 ; sqrNum [ i ] = 1 ; k = 1 ; while ( k * k <= i ) { if ( arr [ i ] > arr [ i - k * k ] + 1 ) { arr [ i ] = arr [ i - k * k ] + 1 ; sqrNum [ i ] = k * k ; } k ++ ; } } while ( n > 0 ) { v . Add ( sqrNum [ n ] ) ; n -= sqrNum [ n ] ; } return v ; } public static void Main ( String [ ] args ) { int n = 10 ; List < int > v ; v = minSqrNum ( n ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { Console . Write ( v [ i ] ) ; if ( i + 1 != v . Count ) Console . Write ( " ▁ + ▁ " ) ; } } }