POJ 3486 & HDU 1913 Computers(dp)
题目链接:PKU:HDU:
PKU:http://poj.org/problem?id=3486
HDU: pid=1913" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=1913
Description
Everybody is fond of computers, but buying a new one is always a money challenge. Fortunately, there is always a convenient way to deal with. You can replace your computer and get a brand new one, thus saving some maintenance cost. Of course, you must pay
a fixed cost for each new computer you get.
Suppose you are considering an n year period over which you want to have a computer. Suppose you buy a new computer in year y, 1<=y<=n Then you have to pay a fixed cost c, in the year y, and a maintenance cost m(y,z) each
year you own that computer, starting from year y through the year z, z<=n, when you plan to buy - eventually - another computer.
Write a program that computes the minimum cost of having a computer over the n year period.
Input
The program input is from a text file. Each data set in the file stands for a particular set of costs. A data set starts with the cost c for getting a new computer. Follows the number n of years, and the maintenance costs m(y,z), y=1..n, z=y..n.
The program prints the minimum cost of having a computer throughout the n year period.
White spaces can occur freely in the input. The input data are correct and terminate with an end of file.
Output
For each set of data the program prints the result to the standard output from the beginning of a line.
Sample Input
3
3
5 7 50
6 8
10
Sample Output
19
Hint
An input/output sample is shown above. There is a single data set. The cost for getting a new computer is c=3. The time period n is n=3 years, and the maintenance costs are:
- For the first computer, which is certainly bought: m(1,1)=5, m(1,2)=7, m(1,3)=50,
- For the second computer, in the event the current computer is replaced: m(2,2)=6, m(2,3)=8,
- For the third computer, in the event the current computer is replaced: m(3,3)=10.
Source
题意:
有个人想在不同的时期分别买一台新电脑,使用这些电脑N年。
每台电脑每年都有维护费用,每买一台电脑时。都要花固定的成本C。
求出使用N年的最少钱是多少。
PS:
dp分段更新从第一年到第n年的过程中每一年的值。
代码例如以下:
#include <cstdio>
#include <algorithm>
using namespace std;
int mp[1017][1017];
int main()
{
int c, y;
while(scanf("%d",&c)!=EOF)
{
scanf("%d",&y);
for(int i = 1; i <= y; i++)
{
for(int j = i; j <= y; j++)
{
scanf("%d",&mp[i][j]);
}
} for(int i = 1; i <= y; i++)
{
for(int j = 1; j <= i; j++)
{
mp[1][i] = min(mp[1][j-1]+mp[j][i]+c,mp[1][i]);
}
}
printf("%d\n",mp[1][y]+c);
}
return 0;
}
POJ 3486 & HDU 1913 Computers(dp)的更多相关文章
- HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)
Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...
- POJ 3267:The Cow Lexicon(DP)
http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submi ...
- HDU 3008 Warcraft(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...
- hdu 2059 龟兔赛跑(dp)
龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...
- HDU 2059 龟兔赛跑 (dp)
题目链接 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击--赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4945 2048(dp)
题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...
- HDU 5791 Two (DP)
Two 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5791 Description Alice gets two sequences A and ...
- HDU 2340 Obfuscation(dp)
题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...
随机推荐
- CentOS7 设置开机直接进入命令行界面
上网查询centsos设置开机直接进入命令行界面的方法都说修改/etc/inittab文件,将文件中的“ :id:5:initdefault:”改为“ :id:3:initdefault:”,即将默认 ...
- user namespace 2
昨天又试了一下, echo 0 1000 1 > /proc/<PID>/uid_map 想着直接把一个进程的uid设置成root,这样他就可以在自己的user namespace ...
- [UOJ#348][WC2018]州区划分
[UOJ#348][WC2018]州区划分 试题描述 小 \(S\) 现在拥有 \(n\) 座城市,第ii座城市的人口为 \(w_i\),城市与城市之间可能有双向道路相连. 现在小 \(S\) 要将这 ...
- Python空间数据处理环境搭
Python空间数据处理环境搭 Conda的下载和安装 什么是Conda? 官方定义:Package, dependency and environment management for any la ...
- BZOJ3238 [Ahoi2013]差异 【后缀数组 + 单调栈】
题目链接 BZOJ3238 题解 简单题 经典后缀数组 + 单调栈套路,求所有后缀\(lcp\) #include<iostream> #include<cstdio> #in ...
- spring in action 学习笔记十四:用纯注解的方式实现spring mvc
在讲用纯注解的方式实现springmvc之前先介绍一个类:AbstractAnnotationDispatcherServletInitializer.这个类的作用是:任何一个类继承AbstractA ...
- 汕头市队赛 SRM 07 A 你的麻将会排序吗
A 你的麻将会排序吗 SRM 07 曾经有过一些沉迷日麻的小孩纸,后来呀,他们都去寻找自己的世界了. kpm也是这样的小孩纸.他想有一只自动整理牌的机器.当麻将以给定的顺序进入机器时,通过机器的运转, ...
- Html5学习进阶四 表单元素和表单属性
HTML5 的新的表单元素: HTML5 拥有若干涉及表单的元素和属性. 本章介绍以下新的表单元素: datalist keygen output 浏览器支持 Input type IE Firefo ...
- Java错误随手记
一.Eclipse启动时提示: An internal error occurred during: "Initializing Java Tooling" 1.关闭Eclipse ...
- functools模块方法学习(1):partial
函数的partial应用 典型的,函数在执行时,要带上所有必要的参数进行调用.然后,有时参数可以在函数被调用之前提前获知.这种情况下,一个函数有一个或多个参数预先就能用上,以便函数能用更少的参数进行调 ...