wow2.43猎人装备:排列组合(一)
来源:百度文库 编辑:偶看新闻 时间:2024/05/22 00:44:08
#include
#include
using namespace std;
class Combination
{
private:
int array_count;
vector mset;
bool first;
int position;
public:
Combination(int n, int m)
{
array_count = m;
first = true;
position = n - 1;
for (int i = 0; i < n; i++)
{
mset.push_back( i + 1);
}
}
bool hasnext()
{
return mset[0] < array_count - mset.size() + 1;
}
vector next()
{
if(first)
{
first = false;
return mset;
}
if (mset[mset.size() - 1] == array_count)
position--;
else
position = mset.size() - 1;
mset[position]++;
for (int i = position + 1; i < mset.size(); i++)
{
mset[i] = mset[i - 1] + 1;
}
return mset;
}
};
int main()
{
Combination combination = Combination(5,10);
while (combination.hasnext())
{
vector set = combination.next();
for (int i = 0; i < set.size(); i++)
{
cout << set[i] << "\t";
}
cout << endl;
}
return 0;
}
10选5的组合方式
#include
using namespace std;
class Combination
{
private:
int array_count;
vector
bool first;
int position;
public:
Combination(int n, int m)
{
array_count = m;
first = true;
position = n - 1;
for (int i = 0; i < n; i++)
{
mset.push_back( i + 1);
}
}
bool hasnext()
{
return mset[0] < array_count - mset.size() + 1;
}
vector
{
if(first)
{
first = false;
return mset;
}
if (mset[mset.size() - 1] == array_count)
position--;
else
position = mset.size() - 1;
mset[position]++;
for (int i = position + 1; i < mset.size(); i++)
{
mset[i] = mset[i - 1] + 1;
}
return mset;
}
};
int main()
{
Combination combination = Combination(5,10);
while (combination.hasnext())
{
vector
for (int i = 0; i < set.size(); i++)
{
cout << set[i] << "\t";
}
cout << endl;
}
return 0;
}
10选5的组合方式