HDU - 1300 简单DP

题意:买珠子的方案有两种,要么单独买,价钱为该种类数量+10乘上相应价格,要么多个种类的数量相加再+10乘上相应最高贵的价格买
坑点:排序会WA,喵喵喵?
为什么连续取就是dp的可行方案?我猜的..

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e5+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read()
{
    ll x=0,f=1;register 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;
}
struct A{
	int num,price;
}a[maxn];
bool cmp(A a,A b){
	return a.price<b.price;
}
ll dp[maxn],sum[maxn];
int main(){
	int T=read();
	while(T--){
		int n=read();
		rep(i,1,n){
			a[i].num=read();
			a[i].price=read();
		}
//		sort(a+1,a+1+n,cmp);
		rep(i,1,n) sum[i]=sum[i-1]+a[i].num;
		rep(i,1,n) dp[i]=(sum[i]+10)*a[i].price;
		rep(i,2,n){
			rep(j,1,i-1){
				dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j]+10)*a[i].price);
			}
		}
		println(dp[n]);
	}
	return 0;
}
posted @ 2018-03-06 17:40  Caturra  阅读(133)  评论(0编辑  收藏  举报