题目:http://poj.org/problem?id=2248
大意:序列第一个数为1,之后的每个数都等于之前的任意两个数(可以相同)相加,问最后一个数是N的情况下,求一个最短的序列
思路:
搜索,确定上下界,下界一定不小于log2(N)+1,上届即目前最优序列的长度,搜索时,用每一层搜索最后一个数和之前的数相加
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
#define MAX 101
void Make(int n, set<int>& chain)
{
if(!n || chain.count(n)) return;
chain.insert(n);
int i = 0;
for(; (1 << i) <= n; ++i) chain.insert(1 << i);
--i;
Make(n - (1 << i), chain);
}
template<typename