POJ 3486 & HDU 1913 Computers(dp)
来源:互联网 发布:mysql user host 编辑:程序博客网 时间:2024/05/08 02:07
题目链接:PKU:HDU:
PKU:http://poj.org/problem?id=3486
HDU: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
335 7 506 810
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)
- poj 3486 Computers dp的思想
- HDU 1913 Computers
- HDU 1913 Computers
- hdu acm 1913 Computers
- hdu 1913 computers
- HDU 1913 Computers (解题报告)
- hdu2196 Computers 树形DP
- poj 2410 Simple Computers
- POJ 2410 Simple Computers
- POJ 2410 Simple Computers 笔记
- hdu 3594 Buy Computers【水题】
- hdu 2713 (水dp)|| poj 2181
- Coins (poj 1742 && hdu 2844 DP)
- POJ 1260 && HDU 1300 Pearls(dp)
- HDU POJ 数位DP
- Computers
- POJ 2410:Simple Computers 模拟题
- Set uid, gid,sticky bit的三个权限的详细说明
- Java TreeMap 升序|降序排列
- codeforces C. Diverse Permutation
- 内部类——为什么匿名内部类和局部内部类只能访问final变量
- javaEE tomcat的编码设置
- POJ 3486 & HDU 1913 Computers(dp)
- Fedora下ALSA的编译与安装
- 软功需要用到的几种图
- CF 2013-2014 Samara SAU ACM ICPC Quarterfinal Qualification Contest C.Victor's Research
- 在 Ubuntu 12.04 下编译 GCC 4.7
- ListView 滚动背景变黑
- POJ 3181 Dollar Dayz(完全背包+简单高精度加法)
- UI动画之画布
- LDAP优化配置一例