本博客为洛谷P1120题解,链接如下:
小木棍 - 洛谷https://www.luogu.com.cn/problem/P1120相信有深搜基础的人这道题都可以写出基本代码,但这样提交到洛谷平台上最多也就十几分,所以说这道题肯定要加剪枝(优化),so……
AC代码英文注释版:
#include<bits/stdc++.h>
using namespace std;
int n,a[51],sum,maxx,num,ans;
bool flag;
inline int read(){
int x=0;
char c=getchar();
while(isdigit(c)){
x=(x<<3)+(x<<1)+c-'0';
c=getchar();
}
return x;
}
//Step represents the number of sticks currently being gathered,
//and Len represents the total length of the roots currently gathered.
void dfs(int step,i