zoukankan      html  css  js  c++  java
  • Lighting System Design

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll>PLL;
    typedef pair<int, int>PII;
    typedef pair<double, double>PDD;
    #define I_int ll
    inline ll read()
    {
        ll x = 0, f = 1;
        char ch = getchar();
        while(ch < '0' || ch > '9')
        {
            if(ch == '-')f = -1;
            ch = getchar();
        }
        while(ch >= '0' && ch <= '9')
        {
            x = x * 10 + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
    #define read read()
    #define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
    #define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
    #define rep(i,a,b) for(int i=(a);i<=(b);i++)
    #define repp(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>=(b);i--)
    #define perr(i,a,b) for(int i=(a);i>(b);i--)
    ll ksm(ll a, ll b, ll p)
    {
        ll res = 1;
        while(b)
        {
            if(b & 1)res = res * a % p;
            a = a * a % p;
            b >>= 1;
        }
        return res;
    }
    const int inf = 0x3f3f3f3f;
    #define PI acos(-1)
    const double eps = 1e-8;
    const int maxn =1e3+7;
    struct node{
        int v,k,c,l;
    }a[maxn];
    int n,dp[maxn],sum[maxn];
    bool cmp(node a,node b){
        return a.v<b.v;
    }
    int main(){
    	while(cin>>n){
            if(!n) break;
            rep(i,1,n) cin>>a[i].v>>a[i].k>>a[i].c>>a[i].l;
            sort(a+1,a+1+n,cmp);
            sum[0]=0;
            rep(i,1,n)
                sum[i]=sum[i-1]+a[i].l;
            memset(dp,0x3f,sizeof dp);
            dp[0]=0;
            for(int i=1;i<=n;i++){
                for(int j=0;j<=i;j++){
                    dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j])*a[i].c+a[i].k);
                }
            }
            cout<<dp[n]<<endl;
    	}
    	return 0;
    }
    
    
  • 相关阅读:
    98.公共汽车
    100.选菜(动态规划)01背包
    102.愤怒的LJF
    96.老鼠的旅行(动态规划)
    95.(01背包)之小吃
    94.Txx考试
    93.数字三角形W(深搜)
    POJ 3352 Road Construction (边双连通分量)
    POJ 3114 Countries in War(强联通分量+Tarjan)
    POJ 3592 Instantaneous Transference(强联通分量 Tarjan)
  • 原文地址:https://www.cnblogs.com/OvOq/p/14789555.html
Copyright © 2011-2022 走看看