题目意思:
https://www.luogu.com.cn/problem/P1181
- 相当于是框里装东西,东西有大有小。筐满了,换下一个。问最少用多少个框。
- 对了,次序不能改变。只能1,2,3,4这样去拿
想法
- 贪心:利用贪心。每次尽可能多拿。如果装不下就换。
//P1181 数列分段Section I
// Created by majoe on 2020/4/30.
//https://www.luogu.com.cn/problem/P1181
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
// n为被划分的个数,m为每段最大值,t为临时
int n,m,t,arr[maxn],cnt=1;
int main(){
cin >> n >> m;
for (int i = 1; i <= n ; ++i) {
cin >> arr[i];
}
for (int i = 1; i <=n ; ++i) {
if(t+arr[i]<=m){
t += arr[i];
} else{
cnt++;
t = arr[i];
}
}
cout << cnt;
return 0;
}