有点像贪心
首先按照w/t的大小对n种植物进行从小到大排序,然后根据w/t从大到小遍历,对于每一种植物不断采摘,直到时间不够再采摘,接着下一种植物。
for (int i=n;i>=1;i--){
int maxIndex=(int)b[i][0];
int tm=plants[maxIndex].t;
int wm=plants[maxIndex].w;
while (t-tm>=0){
t-=tm;
ans+=wm;
}
}
这里是遍历的代码,已经排好序了。
没想到为什么会错,希望大佬指出!感谢!!