-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.hpp
41 lines (37 loc) · 819 Bytes
/
Util.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#pragma once
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <functional>
#include <bit>
#include <vector>
#include <unordered_map>
using namespace std;
size_t binomial_coefficient(size_t n, size_t k) // n C k
{
if ( k == 0 || n == 0 )
return 1;
if ( k > n )
return 0;
if ( k > n - k )
return binomial_coefficient(n, n-k); // symmetry!
// otherwise
return ( n * binomial_coefficient(n-1, k-1) ) / k;
}
size_t generate_letter_masks ( vector<string> const& dict,
unordered_map<string, uint>& masks )
{
masks.clear();
uint mask;
for ( string const& word : dict )
{
mask = 0;
for ( char c : word )
{
mask |= (1 << (c-'a'));
}
masks.insert(make_pair(word, mask));
}
return masks.size();
}