题目链接: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 y1<=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 zz<=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..nz=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)=5m(1,2)=7m(1,3)=50,
  • For the second computer, in the event the current computer is replaced: m(2,2)=6m(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;
}

最新文章

  1. Cesium原理篇:Property
  2. java从基础知识(十)java多线程(下)
  3. DirectX9 Sample_Empty Project
  4. Android单例线程池
  5. 充分利用 SQL Server Reporting Services 图表
  6. linux下mysql远程访问
  7. iptables 开启3306端口
  8. JavaScript高级程序设计(第三版)第五章 引用类型
  9. 剑指 offer set 9 包含min函数的栈
  10. c程序设计语言_习题1-13_统计输入中单词的长度,并且根据不同长度出现的次数绘制相应的直方图
  11. sharepoint2010网站根据权限隐藏ribbon
  12. 项目任务管理(TaskMgr)设计篇
  13. C#委托 Lamda表达式
  14. ilmerge合并多个组件
  15. Microsoft Azure 负载平衡服务
  16. 安装Extended WPF Toolkit
  17. Effective C++ ——设计与声明
  18. [CentOS7][ssh][publickey][troubleshoot] 通过密钥登录ssh故障排查
  19. ezmorph将一种对象转换成另外一种对象
  20. Python multiprocessing模块的Pool类来代表进程池对象

热门文章

  1. Nginx 战斗准备 —— 优化指南
  2. php 值传递和引用传递的区别
  3. macOS Mojave 深色模式
  4. P2135 方块消除
  5. Zigzag数组 -- 面试宝典
  6. H3C交换机端口链路聚合
  7. POJ 3461Oulipo KMP模板
  8. AB序列 凹函数的性质
  9. 关于0x*** 十六进制的运算。为什么枚举多用十六进制的运算原因。。
  10. 使用select2插件并添加拼音首字母检索