Leetcode-5176 Number of Valid Words for Each Puzzle(猜字谜)
Posted asurudo
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode-5176 Number of Valid Words for Each Puzzle(猜字谜)相关的知识,希望对你有一定的参考价值。
1 #define _for(i,a,b) for(int i = (a);i < b;i ++) 2 #define _rep(i,a,b) for(int i = (a);i > b;i --) 3 class Solution 4 5 public: 6 vector<int> findNumOfValidWords(vector<string>& words, vector<string>& puzzles) 7 8 map<int,int> m; 9 _for(i,0,words.size()) 10 11 int st = 0; 12 int cnt = 0; 13 _for(j,0,words[i].size()) 14 st |= 1<<words[i][j]-‘a‘; 15 m[st] ++; 16 17 vector<int> vV; 18 19 _for(i,0,puzzles.size()) 20 21 int sup = 0; 22 int rnt = 0; 23 _for(j,0,puzzles[i].size()) 24 sup |= 1<<puzzles[i][j]-‘a‘; 25 int sub = sup; 26 do 27 28 if((sub & (1<<puzzles[i][0]-‘a‘))) 29 rnt += m[sub]; 30 sub = (sub-1) & sup; 31 32 while(sub != sup); // 处理完之后 会有 -1&sup = sup 33 vV.push_back(rnt); 34 35 return vV; 36 37 ;
以上是关于Leetcode-5176 Number of Valid Words for Each Puzzle(猜字谜)的主要内容,如果未能解决你的问题,请参考以下文章
POJ 2699 The Maximum Number of Strong Kings (最大流+枚举)
CodeForces - 724G Xor-matic Number of the Graph
poj2699 The Maximum Number of Strong Kings