Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<math.h>
- #include <algorithm>
- #include<climits>
- using namespace std;
- long long e = 1000000007;
- int monet(int a[], int n, int s)
- {
- int table[1000][100000], i, j, x, y;
- for (i = 0; i<n; i++)
- table[0][i] = 1;
- for (int i = 1; i < s+1; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (i - a[j] >= 0)
- x = (table[i - a[j]][j]);
- else
- x=0;
- if (j >= 1)
- y = table[i][j - 1];
- else
- y = 0;
- table[i][j] = (x + y)%e;
- }
- }
- return table[s][n - 1];
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int n, s, a[100000];
- cin >> n >> s;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- cout << monet(a, n, s);
- // идею решения подсмотрел на сайте
- //http://www.geeksforgeeks.org/dynamic-programming-set-7-coin-change/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement