HDU1260DP
Tickets
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3780 Accepted Submission(s): 1896
A good approach, reducing the total time of tickets selling, is let adjacent people buy tickets together. As the restriction of the Ticket Seller Machine, Joe can sell a single ticket or two adjacent tickets at a time.
Since you are the great JESUS, you know exactly how much time needed for every person to buy a single ticket or two tickets for him/her. Could you so kind to tell poor Joe at what time could he go back home as early as possible? If so, I guess Joe would full of appreciation for your help.
1) An integer K(1<=K<=2000) representing the total number of people;
2) K integer numbers(0s<=Si<=25s) representing the time consumed to buy a ticket for each person;
3) (K-1) integer numbers(0s<=Di<=50s) representing the time needed for two adjacent people to buy two tickets together.
题意:
处理k件事依次排列,每有一个件事单独处理时间,又知道相邻的两件事同时处理的时间,问这k件事最少的处理时间
代码:
//每件事考虑单独处理和他与前一个同时处理两种情况,dp求最小即可。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int f[][],n,k,a[],b[];
int main()
{
scanf("%d",&n);
while(n--){
scanf("%d",&k);
for(int i=;i<=k;i++) scanf("%d",&a[i]);
for(int i=;i<=k;i++) scanf("%d",&b[i]);
f[][]=a[];f[][]=a[];
for(int i=;i<=k;i++){
f[][i]=min(f[][i-]+a[i],f[][i-]+a[i]);
f[][i]=f[][i-]-a[i-]+b[i];
}
int sum=min(f[][k],f[][k]);
int se=sum%;
int mi=(sum/)%;
int ho=((sum/)/)%+;
int x1,x2,x3,x4,x5,x6,flag=;
if(ho>) {ho-=;flag=;};
x1=ho/;x2=ho%;x3=mi/;x4=mi%;x5=se/;x6=se%;
printf("%d%d:%d%d:%d%d ",x1,x2,x3,x4,x5,x6);
if(flag) printf("pm\n");
else printf("am\n");
}
return ;
}
HDU1260DP的更多相关文章
随机推荐
- 01背包问题:DP
题目描述: 有 N 件物品和一个容量是 V 的背包.每件物品只能使用一次. 第 i 件物品的体积是 vi,价值是 wi. 求解将哪些物品装入背包,可使这些物品的总体积不超过背包容量,且总价值最大.输出 ...
- Linear Equations in Linear Algebra
Linear System Vector Equations The Matrix Equation Solution Sets of Linear Systems Linear Indenpende ...
- [转载]Java集合框架的常见面试题
http://www.jfox.info/40-ge-java-ji-he-lei-mian-shi-ti-he-da-an 整理自上面链接: Java集合框架为Java编程语言的基础,也是Java面 ...
- Hadoop学习(一):完全分布式集群环境搭建
1. 设置免密登录 (1) 新建普通用户hadoop:useradd hadoop(2) 在主节点master上生成密钥对,执行命令ssh-keygen -t rsa便会在home文件夹下生成 .ss ...
- 最长回文子串计算(fail)
题意: 给定一个字符串s,在s中找到最长的回文子字符串.您可以假设s的最大长度为1000. 例子: 输入: “babad” 输出: “bab” 注: “aba”也是一个有效的答案. 我的答案: 想法: ...
- TCP系列21—重传—11、TLP
一.介绍 Tail Loss Probe (TLP)是同样是一个发送端算法,主要目的是使用快速重传取代RTO超时重传来处理尾包丢失场景.在一些WEB业务中,如果TCP尾包丢失,如果依靠RTO超时进行重 ...
- 《学习OpenCV》课后习题解答4
题目:(P104) 练习使用感兴趣区域(ROI).创建一个210*210的单通道图像并将其归0.在图像中使用ROI和cvSet()建立一个增长如金字塔状的数组.也就是:外部边界为0,下一个内部边界应该 ...
- sublime text 3103 怎么设置中文
1.shift+ctrl+p调出插件管理,输入install package,按enter键,开始安装. 2.搜索chinese即可,下载安装插件包即可 原文:http://blog.csdn.net ...
- java-实用的sql语句
一.在数据库创建表格的SQL语句 1,创建一个link表格,包含属性:lid 主键,title 标题, imgpath 图片地址 , url 网址 , info 说明, isshow 显示1 ...
- c++:error2019,无法解析的外部命令blabla~
出现这个原因的问题汇总: 1,相应的附加库没有包含进去,注意附加库的目录是 / 2,函数没有与之对应的类,却在main中以某一类的对象调用了该方法. 其实,当错误中显示fun()成为无法解析的外部命令 ...