HDU 1300 Pearls(dp)

来源:互联网 发布:js基本表单的前台验证 编辑:程序博客网 时间:2024/05/22 14:32
这题题目里说了,给出的数据是有一定递增的,所以不用排序。
////  main.cpp//  Richard////  Created by 邵金杰 on 16/9/25.//  Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;const int maxn=1000+5;struct node{    int a,p;}c[maxn];ll dp[maxn];int main(){    int t;    scanf("%d",&t);    while(t--)    {        int n;        scanf("%d",&n);        for(int i=1;i<=n;i++) dp[i]=9999999999999999;        for(int i=1;i<=n;i++) scanf("%d%d",&c[i].a,&c[i].p);        dp[0]=0;        for(int i=1;i<=n;i++)        {            ll sum=c[i].a;            for(int j=i-1;j>=0;j--)            {                dp[i]=min(dp[i],(sum+10)*c[i].p+dp[j]);                sum+=c[j].a;            }        }        cout<<dp[n]<<endl;    }    return 0;}

0 0
原创粉丝点击