码迷,mamicode.com
首页 > 其他好文 > 详细

组合数计算

时间:2018-08-17 20:02:28      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:ace   pac   nbsp   重复   d3d   none   ++   vat   open   

技术分享图片
 1 #include <iostream>
 2 #include <unordered_map>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 class Solution
10 {
11     private:
12         int need_typesize;
13         int total_typesize = 43;
14         int result = 0;
15     public:
16         int DFS(int number)
17         {
18             need_typesize = number;
19             vector<int> tmp;
20             _DFS(0,tmp);
21             return result;
22         }
23         void _DFS(int start,vector<int>& tmp)
24         {
25             if(tmp.size()==need_typesize)
26             {
27                 result ++;
28             }
29             else if(tmp.size()<need_typesize)
30             {
31                 for(int i = start;i < total_typesize;i ++)
32                 {
33                 //    vector<int> tmp2 = tmp;
34                 //    _DFS(start+1,tmp2);
35                     tmp.emplace_back(i);
36                     _DFS(start+1,tmp);
37                     tmp.pop_back();
38                 }
39             }
40         }
41 };
42 
43 int main()
44 {
45     Solution obj;
46     int result = obj.DFS(3);
47     cout << result << endl;
48 //    for(auto v:result)
49 //    {
50 //        for(auto s:v)
51 //        {
52 //            cout << s << " ";
53 //        }
54 //        cout << endl;
55 //    }
56     return 0;
57 }
有顺序没重复
技术分享图片
 1 #include <iostream>
 2 #include <unordered_map>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 class Solution
10 {
11     private:
12         int need_typesize;
13         int total_typesize = 23;
14         int result = 0;
15     public:
16         int DFS(int number)
17         {
18             need_typesize = number;
19             vector<int> tmp;
20             _DFS(tmp);
21             return result;
22         }
23         void _DFS(vector<int>& tmp)
24         {
25             if(tmp.size()==need_typesize)
26             {
27                 result ++;
28             }
29             else if(tmp.size()<need_typesize)
30             {
31                 for(int i = 0;i < total_typesize;i ++)
32                 {
33                 //    vector<int> tmp2 = tmp;
34                 //    _DFS(start+1,tmp2);
35                     tmp.emplace_back(i);
36                     _DFS(tmp);
37                     tmp.pop_back();
38                 }
39             }
40         }
41 };
42 
43 int main()
44 {
45     Solution obj;
46     int result = obj.DFS(6);
47     cout << result << endl;
48 //    for(auto v:result)
49 //    {
50 //        for(auto s:v)
51 //        {
52 //            cout << s << " ";
53 //        }
54 //        cout << endl;
55 //    }
56     return 0;
57 }
有顺序有重复
技术分享图片
 1 #include <iostream>
 2 #include <unordered_map>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 class Solution
10 {
11     private:
12         int need_typesize;
13         int total_typesize = 19;
14         int result = 0;
15     public:
16         int DFS(int number)
17         {
18             need_typesize = number;
19             vector<int> tmp;
20             _DFS(0,tmp);
21             return result;
22         }
23         void _DFS(int start,vector<int>& tmp)
24         {
25             if(tmp.size()==need_typesize)
26             {
27                 result ++;
28             //    for(auto d:tmp)
29             //        cout << d << " ";
30             //    cout << endl;
31             }
32             else if(tmp.size()<need_typesize)
33             {
34                 for(int i = start;i < total_typesize;i ++)
35                 {
36                 //    vector<int> tmp2 = tmp;
37                 //    _DFS(start+1,tmp2);
38                     tmp.emplace_back(i);
39                     _DFS(i,tmp);
40                     tmp.pop_back();
41                 }
42             }
43         }
44 };
45 
46 int main()
47 {
48     Solution obj;
49     int result = obj.DFS(6);
50     cout << result << endl;
51 //    for(auto v:result)
52 //    {
53 //        for(auto s:v)
54 //        {
55 //            cout << s << " ";
56 //        }
57 //        cout << endl;
58 //    }
59     return 0;
60 }
没顺序有重复
技术分享图片
 1 #include <iostream>
 2 #include <unordered_map>
 3 #include <algorithm>
 4 #include <vector>
 5 #include <queue>
 6 
 7 using namespace std;
 8 
 9 class Solution
10 {
11     private:
12         int need_typesize;
13         int total_typesize = 19;
14         int result = 0;
15     public:
16         int DFS(int number)
17         {
18             need_typesize = number;
19             vector<int> tmp;
20             _DFS(0,tmp);
21             return result;
22         }
23         void _DFS(int start,vector<int>& tmp)
24         {
25             if(tmp.size()==need_typesize)
26             {
27                 result ++;
28             //    for(auto d:tmp)
29             //        cout << d << " ";
30             //    cout << endl;
31             }
32             else if(tmp.size()<need_typesize)
33             {
34                 for(int i = start;i < total_typesize;i ++)
35                 {
36                 //    vector<int> tmp2 = tmp;
37                 //    _DFS(start+1,tmp2);
38                     tmp.emplace_back(i);
39                     _DFS(i+1,tmp);
40                     tmp.pop_back();
41                 }
42             }
43         }
44 };
45 
46 int main()
47 {
48     Solution obj;
49     int result = obj.DFS(6);
50     cout << result << endl;
51 //    for(auto v:result)
52 //    {
53 //        for(auto s:v)
54 //        {
55 //            cout << s << " ";
56 //        }
57 //        cout << endl;
58 //    }
59     return 0;
60 }
没顺序没重复

 

组合数计算

标签:ace   pac   nbsp   重复   d3d   none   ++   vat   open   

原文地址:https://www.cnblogs.com/Asurudo/p/9494852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!