HDU1300DP
/*
HDU1300 DP
特定n饰品种类
每个饰品的两个数据。amount[i]代表数量。price[i]代表单位价格
购买珠宝时要满足下面购买规则:
单独买:每种珠宝要加上数量10
合并买:能够把连续几种珠宝数量合并,再加上10,单位价格依照price最大的计算
求出购买全部的珠宝最少要花费多少 思路: 初始化:第一种珠宝 仅仅须要管当前第i种珠宝的购买
购买方法一:前i-1种依照前面的最优值购买(无后效性),第i种单独买
则: dp[i]=dp[i-1]+price[i]*(amount[i]+10);
购买方法二:从第j种到第i种数量合并购买,当中j从1取到i
则: dp[i]=dp[j-1]+(amount_tot[i]-amount_tot[j-1]+10)*price[i]; 结果:dp[n]
*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
using namespace std; #define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
#define For1(i,a,b) for (i=a;i<b;i++)
#define For2(i,a,b) for (i=a;i<=b;i++)
#define Dec(i,a,b) for (i=a;i>b;i--)
#define Dec2(i,a,b) for (i=a;i>=b;i--)
#define Sca_d(x) scanf("%d",&x)
#define Sca_s(x) scanf("%s",x)
#define Sca_c(x) scanf("%c",&x)
#define Sca_f(x) scanf("%f",&x)
#define Sca_lf(x) scanf("%lf",&x)
#define Fill(x,a) memset(x,a,sizeof(x))
#define MAXN 1005
#define MAXINT 99999999 int main()
{
//input;
int i,j,n,k,t;
int amount[MAXN],amount_tot[MAXN],price[MAXN];
//注意:amount_tot[k]指的是从第1种到第k种珠宝一共同拥有多少个
//也即前序和
__int64 dp[MAXN];
cin>>t;
while(t--)
{
Fill(amount,0);
Fill(amount_tot,0);
Fill(price,0);
Fill(dp,0);
cin>>n;
For2(i,1,n)
Sca_d(amount[i]),amount_tot[i]=amount_tot[i-1]+amount[i],Sca_d(price[i]);
dp[1]=(amount[1]+10)*price[1];
For2(i,2,n)
{
dp[i]=dp[i-1]+price[i]*(amount[i]+10);
For2(j,1,i)
dp[i]=min(dp[j-1]+(amount_tot[i]-amount_tot[j-1]+10)*price[i],dp[i]);
}
cout<<dp[n]<<endl;
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU1300DP的更多相关文章
随机推荐
- ASP.NET - 用户控件制作
首先添加用户控件: 在里面写上代码: <%@ Control Language="C#" AutoEventWireup="true" CodeBehin ...
- net core VS goang web
asp.net core VS goang web[修正篇] 先前写过一篇文章:http://www.cnblogs.com/gengzhe/p/5557789.html,也是asp.net core ...
- LintCode 二叉树的层次遍历 II
中等 二叉树的层次遍历 II 查看执行结果 42% 通过 给出一棵二叉树,返回其节点值从底向上的层次序遍历(按从叶节点所在层到根节点所在的层遍历,然后逐层从左往右遍历) 您在真实的面试中是否遇到过这个 ...
- Linux账号管理(二)
再次声明,整理此系列Linux博客,主要目的不是介绍各种命令,而是去探索命令背后的理论. 本篇主要介绍用户的创建与删除. 创建用户主要用到useradd命令,在用此命令时可以指定各种参数.一般默认就可 ...
- Linux账号管理(一)
整理自<鸟哥的Linux私房菜>,整理者:华科小涛http://www.cnblogs.com/hust-ghtao/ 管理员的工作中,相当重要的一环就是“管理账号”.因为整个系统都是你在 ...
- Linear Regression(线性回归)(一)—LMS algorithm
(整理自AndrewNG的课件,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 1.问题的引出 先从一个简单的例子说起吧,房地产公司有一些关于Po ...
- MSSQL- select @@identity的用法
转载自:http://blog.163.com/zhangqian_sms/blog/static/544483382008925112539620/ 用select @@identity得到上一次插 ...
- 显示器 Linux 性能 18 (一个命令行工具传递)
对于系统和网络管理员来说每天监控和调试Linux系统的性能问题是一项繁重的工作.在IT领域作为一名Linux系统的管理员工作5年后,我逐渐认识到监控和保持系统启动并执行是多么的不easy.基于此原因. ...
- alv行可编辑时带出描述
ALV显示可以编辑的状态下可以带出描述信息等,比如维护表程序输入公司代码时需要带出公司代码的描述,这时就需要通过下面事件来触发 定义一个类: CLASS lcl_event_receiver DEFI ...
- Block Internet connection
https://www.board4allcz.eu/showthread.php?t=625547