Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- using namespace std;
- const int MAX = 10001;
- int n, m;
- int w[100];
- int mat[100001][101];
- bool f(int mas, int j, int n);
- int main(){
- cin >> n >> m;
- for (int i = 0; i < n; i++)
- cin >> w[i];
- for (int i = 0; i <= m; i++)
- for (int j = 0; j <= n; j++)
- mat[i][j] = -1;
- // "j" is number of golden bars
- for (int mas = 1; mas <= m; mas++){
- for (int i = 0; i < n; i++)
- if (w[i] == mas)
- mat[mas][1] = i;
- for (int j = 2; j <= n; j++){
- for (int i = 0; i < n; i++){
- if (mas - w[i] > 0 && mat[mas - w[i]][j - 1] != -1)
- if (f(mas, j, i)){
- mat[mas][j] = i;
- break;
- }
- }
- }
- }
- bool check = true;
- for (int i = 1; i <= n && check; i++)
- check = mat[m][i] == -1;
- if (check)
- cout << "NO" << endl;
- else
- cout << "YES" << endl;
- return 0;
- }
- bool f(int mas, int j, int n){
- int tmp = w[n];
- while (j > 0 && mas - w[n] > 0){
- mas -= tmp;
- j--;
- if (mat[mas][j] == n)
- return false;
- tmp = w[mat[mas][j]];
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement