您的位置:首页 > 其它

HDU 1300 Pearls(dp)

2016-09-25 09:38 405 查看
这题题目里说了,给出的数据是有一定递增的,所以不用排序。
//
//  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
<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: