A ruler of length 13, if the 1-bit point can be 1 and 12, 133 kinds of scale. So at least a few points, you can directly measure the length of 1-13, which are engraved in which positions?
Note: Must be a direct quantity. That is, the ruler can find a 1-13 arbitrary integer length.
Wrote a no-tech solution to DFS violence. A viable solution is 1, 2, 6, 10.
1#include <iostream>2#include <vector>3#include <unordered_map>4 using namespacestd;5 6 classSolution {7 Public:8vector<vector<int>> Ruler (intN, vector<int> &Minpath) {9Dfs0, N, Minpath);Ten returnresult; One } Avector<vector<int>>result; -vector<int>path; - voidDfsintStartintN, vector<int> &Minpath) { the if(Start = = n +1) { - if(Fullscale (path)) { - result.push_back (path); - if(Path.size () <Minlen) { +Minlen =path.size (); -Minpath =path; + } A } at return; - } - for(inti = start; I <= N; i++) { - Path.push_back (i); -DFS (i +1, N, Minpath); - Path.pop_back (); in } - } to BOOLFullscale (vector<int>path) { + if(Path.size () <4) { - return false; the } *unordered_map<int,int>Umap; $umap[ -]++;Panax Notoginsengumap[0]++; - for(inti =0; I < path.size (); i++) { the for(intj =0; J < I; J + +) { + if(Path[i]-PATH[J] < -) { AUmap[path[i]-path[j]]++; theumap[path[j]]++; +umap[path[i]]++; -umap[ --path[i]]++; $umap[ --path[j]]++; $ } - if(Umap.size () >= -) { - return true; the } - }Wuyi } the return false; - } Wu Private: - intMinlen = -; About }; $ - intMain () { - intn = -; - solution Solu; Avector<int>Minpath; +vector<vector<int>> res =Solu.ruler (n, minpath); the for(Auto X:minpath) { -cout << x <<", "; $ } the}
Ref:https://en.wikipedia.org/wiki/sparse_ruler
Minimal sparse ruler problem minimum ruler scale problem