转载POJ1017-Packets,POJ2393,

POJ1017-Packets - CSDN博客 https://blog.csdn.net/lyy289065406/article/details/6674366
本题除了原作者已经注释的部分,还要注意式子中+3,+8,+35的含义是多余部分也要占一个箱子,这个箱子随后被其他更小的箱子填满,是一个复杂的箱子,但要记得把这个箱子加上,所以加上这几个数既能够保证安排多余的箱子,又能够保证不会凭空多出一个箱子。
POJ-2393-Yogurt factory - CSDN博客 https://blog.csdn.net/z309241990/article/details/9229077
因为第i周的奶酪,可以在第i周生产,也可以在前几周生产,然后储存。通过把s转化为花费,跟原有花费去比较,取一个最小值,这样从头到尾,每一周都可以取得一个花费的最小值。贪心求解。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=10011;
int n,s;
int y[maxn],c[maxn];
int main()
{
    while(scanf("%d%d",&n,&s)!=EOF)
    {
	for(int i=0;i<n;i++)
	    scanf("%d%d",&c[i],&y[i]);
	long long ans=0;
	for(int i=1;i<n;i++)
	    c[i]=min(c[i-1]+s,c[i]);//这一行是关键每一周都贪心地得到至今为止的最小值!
	for(int i=0;i<n;i++)
	    ans+=c[i]*y[i];
	printf("%lld\n",ans);
    }
    return 0;
}

POJ 2376 Cleaning Shifts 贪心 - CSDN博客 https://blog.csdn.net/wmn_wmn/article/details/7909483

猜你喜欢

转载自blog.csdn.net/huaiyingdetective/article/details/82833648