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个单词 ...
随机推荐
- 利用反射修改final数据域
当final修饰一个数据域时,意义是声明该数据域是最终的,不可修改的.常见的使用场景就是eclipse自动生成的serialVersionUID一般都是final的. 另外还可以构造线程安全(thre ...
- [SDOI2017][bzoj4817] 树点涂色 [LCT+线段树]
题面 传送门 思路 $LCT$ 我们发现,这个1操作,好像非常像$LCT$里面的$Access$啊~ 那么我们尝试把$Access$操作魔改成本题中的涂色 我们令$LCT$中的每一个$splay$链代 ...
- chrome性能指标(TTFB,TTSR,TTDC,TTFL)
1.TTFB (Time To First Byte) 是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间. 注意: ...
- vue的main.js
import Vue from 'vue'; import App from './App.vue'; //================http 请求======================= ...
- 使用java的自定义过滤器Filter 处理请求request 并响应response
package com.enation.eop; import java.io.BufferedReader; import java.io.IOException; import java.io.I ...
- Python-Python及PyCharm的下载与安装
一.简介 Python:英 -[‘paɪθ ə n]或[‘paɪθɑn] 89年诞生 可用于软件开发: 游戏后台.搜索.图形界面 网站 C\S(Client/Server)软件 科学计算 亦可以进行系 ...
- Java学习之Iterator(迭代器)
迭代器(Iterator) 迭代器是一种设计模式,它是一个对象,它可以遍历并选择序列中的对象,而开发人员不需要了解该序列的底层结构.迭代器通常被称为“轻量级”对象,因为创建它的代价小. Java中的I ...
- ACdream 1210 Chinese Girls' Amusement(高精度)
Chinese Girls' Amusement Time Limit:1000MS Memory Limit:64000KB 64bit IO Format:%lld & ...
- poj 2187 Beauty Contest(二维凸包旋转卡壳)
D - Beauty Contest Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- greasemonkey
Greasemonkey Hacks/Getting Started < Greasemonkey Hacks Greasemonkey Hacks Foreword Credits Prefa ...