网易校招编程题
写了个深搜:
include
include
include
using namespace std;
vector
{
vector
for (int i = n / 2; i >= 2; i--)
{
if (n % i == 0)
{
res.push_back(i);
}
}
return res;
}
struct jump
{
int n;
int step;
};
int visit(jump j, int M)
{
vector
for (int i = 0; i < nums.size(); ++i)
{
jump temp;
temp.n = j.n + nums[i];
temp.step = j.step + 1;
if (temp.n == M)
return temp.step;
if (temp.n > M)
continue;
int ret= visit(temp, M);
if (ret == -1)
continue;
else
return ret;
}
return -1;
}
int main()
{
int N, M;
while (cin >> N >> M)
{
jump s;
s.n = N;
s.step = 0;
cout << visit(s, M) << endl;
}
}