You are on page 1of 2

#include <bits/stdc++.

h>

#include <stdio.h>

#include <sstream>

#include <iostream>

#include <string>

using namespace std;

#define MAX 1000

int n, M;

int a[MAX];

int PartialTotal = 0;

int countSolution=0;

int extractNumber(string str, int Number[MAX]) {

stringstream str_strm;

str_strm << str;

string temp_str;

int temp_int;

int count = 1;

while (!str_strm.eof()) {

str_strm >> temp_str;

if (stringstream(temp_str) >> temp_int)

{ Number[count] = temp_int;

count = count + 1; }

temp_str = "";

return count-1;

int check(double v,int k)

{
if ( k < n && PartialTotal<=M) return 1;

return PartialTotal + v * a[n] == M;

void Try(int k)

for(int v=1;v<=M/a[k];v++)

if (check(v, k))

PartialTotal += v * a[k];

if (k == n) countSolution++;

else Try(k + 1);

PartialTotal -= v * a[k];

int main()

string inputNumber;

cin >> n >> M;

cin.ignore();

getline(cin,inputNumber);

extractNumber(inputNumber, a);

Try(1);

cout << countSolution;

return 0;

You might also like