Skip to main content

Posts

Showing posts with the label programming

Coin Combinations I CSES dynamic programming problem set solution

 Coin Combinations I CSES dynamic programming problem set solution - Problem statement- Consider a money system consisting of  n n  coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ways you can produce a money sum  x x  using the available coins. For example, if the coins are  { 2 , 3 , 5 } { 2 , 3 , 5 }  and the desired sum is  9 9 , there are  8 8  ways: 2 + 2 + 5 2 + 2 + 5 2 + 5 + 2 2 + 5 + 2 5 + 2 + 2 5 + 2 + 2 3 + 3 + 3 3 + 3 + 3 2 + 2 + 2 + 3 2 + 2 + 2 + 3 2 + 2 + 3 + 2 2 + 2 + 3 + 2 2 + 3 + 2 + 2 2 + 3 + 2 + 2 3 + 2 + 2 + 2 3 + 2 + 2 + 2 Input The first input line has two integers  n n  and  x x : the number of coins and the desired sum of money. The second line has  n n  distinct integers  c 1 , c 2 , … , c n c 1 , c 2 , … , c n : the value of each coin. Output Print one integer: the number of ways modulo  10 9 + 7 10 9 + 7 . Constraints 1 ≤ n ≤ 100 1 ≤ n ≤ 100 1 ≤ x ≤ 10 6 1 ≤ x ≤ 10 6 1 ≤ c i ≤ 10 6 1 ≤ c i ≤ 10 6 Example Input:

Dice Combinations Cses Problem set problem code solution

 Dice Combinations Cses Problem set problem code solution - Dice Combinations Cses Problem set problem code solution  dynamic programming code. Problems statement- Your task is to count the number of ways to construct sum  n n  by throwing a dice one or more times. Each throw produces an outcome between  1 1  and  6 6 . For example, if  n = 3 n = 3 , there are  4 4  ways: 1 + 1 + 1 1 + 1 + 1 1 + 2 1 + 2 2 + 1 2 + 1 3 3 Input The only input line has an integer  n n . Output Print the number of ways modulo  10 9 + 7 10 9 + 7 . Constraints 1 ≤ n ≤ 10 6 1 ≤ n ≤ 10 6 Example Input: 3 Output: 4 link- https://cses.fi/problemset/task/1633/ solution-