目录
一、题目
二、代码
一、题目
幸运的袋子__牛客网
二、代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static int _count = 0;
static int sum = 0;
static int product = 1;
void Combination(vector<int>& v, int start)
{
for (int i = start; i < v.size(); i++)
{
sum += v[i];
product *= v[i];
if (sum > product)
{
_count++;
Combination(v, i + 1);
}
else if (v[i] == 1)
{
Combination(v, i + 1);
}
else
{
//回溯
sum -= v[i];
product /= v[i];
break;
}
//回溯
sum -= v[i];
product /= v[i];
for (; i + 1 < v.size() && v[i] == v[i + 1]; i++);
}
}
int main()
{
int n;
cin >> n;
vector<int> data;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
data.push_back(x);
}
sort(data.begin(), data.end());
Combination(data, 0);
cout << _count;
return 0;
}