Leetcode-5087 Letter Tile Possibilities(活字印刷)

 1 #define _for(i,a,b) for(int i = (a);i < b;i ++)
 2 
 3 class Solution
 4 {
 5     public:
 6         set<string> s;
 7         int numTilePossibilities(string tiles)
 8         {
 9             s.clear();
10             int rnt = 0;
11             for (int S = 1; S < 1 << tiles.size(); S ++)
12             {
13                 string tmp;
14                 _for(i,0,tiles.size())
15                 {
16                     if(S>>i & 0x1)
17                         tmp += tiles[i];
18                 }
19                 sort(tmp.begin(),tmp.end());
20                 do
21                 {
22                     if(!s.count(tmp))
23                     {
24                         rnt ++;
25                         s.insert(tmp);
26                     }
27                 }while(next_permutation(tmp.begin(),tmp.end()));
28             }
29             return rnt;
30         }
31 };

 

posted @ 2019-06-09 12:32  Asurudo  阅读(338)  评论(0编辑  收藏  举报