题目描述
给出N个木块,每个木块有一个长度 a a a,可以被切成若干块长度不一的小木块,现在有M块木料需求,问这N块木块
样例输入
4
30
40
50
25
10
15
16
17
18
19
20
21
25
24
30
样例输出
7
思路
每次二分最终答案
验证就是靠dfs判断是否合法,但是要加上剪枝,要不然会TLE
剪枝:
1.满足不了最小的木料的木块都可以去掉
2.最大的木块都满足不了的木料也都可以去掉
3.木块总量达到不了木料的总量的情况是错的
4.搜索木块的时候,如果上一个木料和当前相同,可以从当前木块开始寻找(因为前面的木块都无法满足当前木料的需求
代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ans = -1e9, n, r, tot;
int sum[1505], a[105], l[1505], c[105];
bool check(int x, int w, int la, int mid)
{
</