• C


    The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_i (1 <= C_i <= 5,000) cents to produce one unit of yogurt in week i. Yucky's factory, being well-designed, can produce arbitrarily many units of yogurt each week.

    Yucky Yogurt owns a warehouse that can store unused yogurt at a constant fee of S (1 <= S <= 100) cents per unit of yogurt per week. Fortuitously, yogurt does not spoil. Yucky Yogurt's warehouse is enormous, so it can hold arbitrarily many units of yogurt.
    Yucky wants to find a way to make weekly deliveries of Y_i (0 <= Y_i <= 10,000) units of yogurt to its clientele (Y_i is the delivery quantity in week i). Help Yucky minimize its costs over the entire N-week period. Yogurt produced in week i, as well as any yogurt already in storage, can be used to meet Yucky's demand for that week.

    Input

    • Line 1: Two space-separated integers, N and S.

    • Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.

    Output

    • Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.

    Sample Input

    4 5
    88 200
    89 400
    97 300
    91 500

    Sample Output

    126900

    Hint

    OUTPUT DETAILS:
    In week 1, produce 200 units of yogurt and deliver all of it. In week 2, produce 700 units: deliver 400 units while storing 300 units. In week 3, deliver the 300 units that were stored. In week 4, produce and deliver 500 units.

    这应该算贪心的思想吧,刚做不清楚;
    就是从这周开始,要不要把接下来几天的也生产掉,对比一下花费就可以了

    #include<iostream>
    #include<stdio.h>
    #include<stdlib.h>
    #include<cmath>
    #include<string.h>
    #include<algorithm>
    #define sf scanf
    #define pf printf
    #define pb push_back
    #define mm(a,b) memset((a),(b),sizeof(a))
    #include<vector>
    const double pi=acos(-1.0);
    typedef __int64 ll;
    typedef long double ld;
    const ll MOD=1e9+7;
    using namespace std;
    int num[10005],n,s,cost[10005],d[10005];
    int main()
    {
    	mm(num,0);
    	mm(cost,0);
    	mm(d,0);
    	cin>>n>>s;
    	for(int i=0;i<n;i++)
    	sf("%d%d",&cost[i],&num[i]);
    	for(int i=0;i<n;i++)
    	{
    		int ans=0;
    		for(int j=1;j<n-i;j++)
    		{
    			if(cost[i]*num[i+j]+num[i+j]*j*s<cost[i+j]*num[i+j])
    			{
    				ans++;
    			}else
    			break;
    		}
    		if(ans)
    		{
    			
    			for(int j=0;j<=ans;j++)
    			{
    				d[i]+=num[i+j];
    			}
    			i+=ans;
    		}else
    		d[i]=num[i];
    	}
    	ll sum=0,tot=0;
    	for(int i=0;i<n;i++)
    	{
    		sum+=d[i]*cost[i]+tot*s;
    		tot=tot+d[i]-num[i];
    		}
    	
    	pf("%I64d",sum);
    	return 0;
    }
    
  • 相关阅读:
    2013.10.21—2013.10.25周总结
    2013.10.14—2013.10.18周总结
    2013.10.8—2013.10.12周总结
    MongoDb的“not master and slaveok=false”错误及解决方法,读写分离
    python 获取当前时间
    git命令与github使用
    s​s​h​配​置​公​钥​和​私​钥​登​陆​S​e​c​u​r​e​C​R​T
    关于pydev的语法的错误提示
    lnmp1.0 升级php.5.4.28 后出错 Nginx 502 Bad Gateway
    python线程Example
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9349123.html
Copyright © 2020-2023  润新知