题目链接 :
解题思路:直接模拟, 记录已经使用的箱子的剩余容量, 如果已经使用的箱子中没有可以放下物品的箱子, 在增加另一个箱子. 最坏情况下N的箱子都要使用, 不会有N个箱子都不够用的情况(i.e. 其中si为满足1<= si<=100的整数).
代码如下(有注释):
#includeusing namespace std;int leave[1005];//记录每个箱子的剩余量,初始为100(最多有1000个箱子) int main(){ int n; cin>>n; for(int i=1;i<=n;i++) { leave[i]=100; } int temp,cnt=1,flag; cin>>temp; leave[1]-=temp; cout< <<" "<<1< >temp; for(int j=1;j<=cnt;j++) { if(leave[j]>=temp) { leave[j]-=temp; cout< <<" "< <