题目链接: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;
}

POJ 3486 &amp; HDU 1913 Computers(dp)的更多相关文章

  1. 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 ...

  2. POJ 3267:The Cow Lexicon(DP)

    http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

  3. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

  4. hdu 2059 龟兔赛跑(dp)

    龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...

  5. HDU 2059 龟兔赛跑 (dp)

    题目链接 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击--赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...

  6. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. HDU 4945 2048(dp)

    题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...

  8. HDU 5791 Two (DP)

    Two 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5791 Description Alice gets two sequences A and ...

  9. HDU 2340 Obfuscation(dp)

    题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...

随机推荐

  1. 【bzoj4562】[Haoi2016]食物链 拓扑排序+dp

    原文地址:http://www.cnblogs.com/GXZlegend/p/6832118.html 题目描述 如图所示为某生态系统的食物网示意图,据图回答第1小题 现在给你n个物种和m条能量流动 ...

  2. 【BestCoder #45】

    用家里的电脑来编程,各种不算 一开始15分钟刷掉T1和T2,然后就永远地卡在了T3... 后来看题解,傻了眼... 它强调的“只有一个答案”我还以为这是在提示我二分答案,于是我一直往权值线段树那个方向 ...

  3. [xsy1129] flow [树链剖分和线段树一起优化网络流][我也不知道这是什么鬼标签]

    题面 内部OJ 思路 考虑一个决策方案${x}$,$x_i$表示第$i$个点选不选,$f^k_i$表示点$i$的第$k$个父亲 那么可以得到总花费的表达式$ans=\sum V_i x_i - \su ...

  4. 接水果(fruit)

    接水果(fruit) 风见幽香非常喜欢玩一个叫做 osu! 的游戏,其中她最喜欢玩的模式就是接水果.由于她已经 DT FC 了 The big black,她觉得这个游戏太简单了,于是发明了一个更加难 ...

  5. Vue组件中的单项数据流

    当子组件中的input v-model 父组件的值时不能直接绑定props的值要使用计算属性,向下面的写法,因为props是单项数据流,子组件不能改变父组件的状态,直接绑定会报错. 还可以这样写:但是 ...

  6. (转)Ant使用例子

    文章来自:http://www.blogjava.net/feng0801/archive/2014/07/29/416297.html Ant是一个Apache基金会下的跨平台的构件工具,它可以实现 ...

  7. [SCOI2005]互不侵犯 (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 位国王,且最后一位状态为 \(k\) . 然后就可以很轻松的转移了 ...

  8. ie8 不支持media

    可以用respond.js库解决,bootstrap文件夹里有.同时需要注意以下几点. 1.需要启动本地服务器(localhost),不能使用普通本地的url地址(file://开头): 2.需要外部 ...

  9. Linux Ubuntu mysql 乱码

    进入mysql后,敲入命令status,就可以看到mysql的字符编码问题. 默认如下: Server characterset:    latin1 Db  characterset:    lat ...

  10. mySql 查询当天、本周、最近7天、本月、最近30天的语句

    mySql 查询当天.本周.最近7天.本月.最近30天的语句 原创 2017年04月13日 16:40:38 标签: 962 编辑 删除 -- 当天 SELECT * FROM  表名 WHERE w ...