题目链接: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. PHP session 与cookie

    知识点: session是将服务器将网页产生的会话信息以数组形式存到一个php文件中,产生的全局变量,可以在系统下的其他网页任意调用这个数据. cookie类似于session原理,但是是将数据存给用 ...

  2. docker 生成新的镜像

    下载了ubuntu的初始化镜像,但是没有网络安装包,安装了字后,如果生成新的镜像 sudo docker commit -m "add ifconfig/ping package" ...

  3. shit vue-cli & path bug & baseUrl bug

    vue-cli path bug https://cli.vuejs.org/zh/guide/#cli baseUrl bug baseUrl: "././" , https:/ ...

  4. jQuery仿3D旋转木马效果插件(带索引按钮)

    项目中需要用到旋转木马效果,但是我在网上找的插件,基本都是不带按钮或者只是带前后按钮的,而项目要求的是带索引按钮,也就是说有3张图片轮播,对应的要有3个小按钮,点击按钮,对应的图片位于中间位置.于是就 ...

  5. Codeforces755D PolandBall and Polygan

    题目戳这里 我们只需要计算每增加一条线后穿过了几条已有的线即可.为了方便,我们令\(K \le N/2\),并且给每条线一个方向,即\(x\)到\((x+K) \; mod \; N\).然后我们假设 ...

  6. Windows2008下RDP采用私有CA服务器证书搭建文档

    在中小型公司建立企业根证书颁发机构 (CA) http://www.microsoft.com/china/smb/issues/sgc/articles/build_ent_root_ca.mspx ...

  7. 求强连通块_Tarjan算法_C++

    好久没有写算法了,就放一个 Tarjan 上来凑凑数哈 强连通块由若干个点组成,任意点与点之间可以之间或间接到达,显然可以看作一个环 下面是伪代码 强记:dfn为时间不变,low取最小,下一个dfn有 ...

  8. 插件 原生js 省市区 三级联动 源码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. calc(NOIP模拟赛Round 3)

    原题: D e s c r i p t i o n 给三个正整数n,m和p,求(n^1+...n^m) mod p. Input 一行,三个整数n,m和p. Output 输出答案. S a m p ...

  10. Altium Designer 网络连接方式Port和Net Label详解

    1.图纸结构      图纸包括两种结构关系: 一种是层次式图纸,该连接关系是纵向的,也就是某一层次的图纸只能和相邻的上级或下级有关系:另一种是扁平式图纸,该连接关系是横向的,任何两张图纸之间都可以建 ...