TA的每日心情 | 开心 昨天 06:36 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
管理员
- 积分
- 1308
|
- static vector<vector<double>> combination(vector<double> arr,int m)
- {
- vector<vector<double>>arrs;
- if (arr.size()>0 && m > 0)
- {
- vector<double> cdr = arr;
- cdr.erase(cdr.begin());
- vector<vector<double>> tmparrs1=combination(cdr,m-1);
- if (tmparrs1.size()==0 && m ==1)
- {
- vector<double> tmp;
- tmp.push采用back(arr.at(0));
- arrs.push采用back(tmp);
- }
- else
- {
- for (int i=0;i<tmparrs1.size();i++)
- {
- tmparrs1.at(i).insert(tmparrs1.at(i).begin(),arr.front());
- }
- arrs.insert(arrs.begin(),tmparrs1.begin(),tmparrs1.end());
- }
- vector<vector<double>> tmparrs2 = combination(cdr,m);
- if (!tmparrs2.size()==0)
- {
- arrs.insert(arrs.begin(),tmparrs2.begin(),tmparrs2.end());
- }
- }
- return arrs;
- }
- static void Combination(const vector<double>v, const int num,vector<vector<double>>result)
- {
- if (v.empty()) {
- return;
- }
- else if (v.size() == 1) {
- result.push采用back(v);
- return;
- }
- //求不同长度的组合
- vector<double> temp采用v;
- for (int i = num; i <= v.size(); ++i) {
- Combination采用n(v, temp采用v, 0, i, result);
- }
- }
复制代码 |
|