Problem:
Consider a money system consisting of coins. Each coin has a positive integer value. Your task is to calculate the number of distinct ways you can produce a money sum using the available coins.
For example, if the coins are and the desired sum is , there are ways:
Input
The first input line has two integers and : the number of coins and the desired sum of money.
The second line has distinct integers : the value of each coin.
Output
Print one integer: the number of ways modulo .
Constraints
Example
Input:3 9
2 3 5
Output:8
Full Explanation:
CODE:
#include <iostream> #include<bits/stdc++.h> using namespace std; int main() { int n=0,x=0; cin>>x>>n; int dice[x]; for(int i=0 ; i<x ; i++){ cin>>dice[i]; } long long value[n+1]; value[0] = 1; for(int i=1;i<=n;i++){ value[i] = 0; for (auto c:dice){ if(i-c >=0){ value[i]+=(value[i-c]%1000000007); } } } cout<<value[n]%(1000000007); return 0; }
No comments:
Post a Comment