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的更多相关文章
随机推荐
- C++汉字转拼音(转)
#include<iostream> #include<string> using namespace std; string findLetter(int nCode); s ...
- Ruby on Rails 實戰聖經阅读(三)
由于是1.8.x:圣经的1.9.3差太多,所以另外按1.8.X来创建hello world 第一個Hello World!! 1. 创建项目rails -d mysql first 2.创建控制器 ...
- EasyUI - Dialog 对话框
效果: html代码: 其中有class加载方式和Javascript加载方式. <!--class加载方式--> <%--<div id="dd" cla ...
- IIS中asp网站播放flv视频技术
播放flv视频文件需要使用flvplayer.swf程序(32K). HTML嵌入代码: <div id="FlashFile"> <object type=&q ...
- Android 仿 窗帘效果 和 登录界面拖动效果 (Scroller类的应用) 附 2个DEMO及源码
在android学习中,动作交互是软件中重要的一部分,其中的Scroller就是提供了拖动效果的类,在网上,比如说一些Launcher实现滑屏都可以通过这个类去实现.下面要说的就是上次Scroller ...
- 创建采购订单批到程序用的BAPI
CALL FUNCTION 'BAPI_PO_CREATE1' EXPORTING poheader = poheader poheaderx = poheaderx * POADDRVENDOR = ...
- tomcat7 启动报错(转)
不加载任何自己的项目启动即报错: 严重: Error deploying web application directory D:\tomcat7.0.30\webapps\docs java.l ...
- flashcache中应用device mapper机制
Device Mapper(DM)是Linux 2.6全面引入的块设备新构架,通过DM可以灵活地管理系统中所有的真实或虚拟的块设备. DM以块设备的形式注册到Linux内核中,凡是挂载(或者说“映射” ...
- Bootstrap验证控件的使用
前端HTML代码 <form id="myForm" method="post" class="form-horizontal" ac ...
- 获取option中间的值
<select name="wytype" id="wytype"> <option value="">—请选择—& ...