#include<iostream>
#include<string>
#include<fstream>
using namespace std;
static int target, n;
static int result;
static int digit[8];
static int instant[8];
static int solution[8];
static int p;
static int splits;
static int mmax;
//#define DEBUG
static void search_dfs(int exist, int cur, int sum)
{
if (sum > target)
return;
if (cur >= n)
{
if (sum == mmax)
{
result++;
// target = -1;
}
else if (sum > mmax)
{
mmax = sum;
int i;
splits = p; result = 1;
for (i = 0; i < p; i++)
{
solution[i] = instant[i];
}
}
}
else
{
int tmp = exist * 10 + digit[cur]; // if tmp > target ?
instant[p++] = tmp;
search_dfs(0, cur + 1, sum + tmp);
instant[p--] = 0;
if (cur < n - 1)
search_dfs(tmp, cur + 1, sum);
}
}
int main()
{
#ifdef DEBUG
fstream cin("G:\\book\\algorithms\
POJ 1416 碎纸机
最新推荐文章于 2021-07-03 18:43:42 发布
博客介绍了如何解决POJ 1416问题,即对一个数字进行分割,使得分割后的数字之和不超过目标值并尽可能接近目标值。通过深度优先搜索算法进行求解,并实施了剪枝策略以优化搜索过程。整个搜索空间可视作一个满二叉树,在不剪枝的情况下。博客提供了具体的搜索路径示例,有助于理解和应用类似问题的解决方案。
摘要由CSDN通过智能技术生成