ZCMU-1404-Computers
来源:互联网 发布:阿里丁丁 mac 编辑:程序博客网 时间:2024/05/21 06:40
1404: Computers
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 26 Solved: 15
[Submit][Status][Web Board]
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. All integers in the problem are bigger than 0 and no more than 1000.
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
Sample Output
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.
#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int main(){ int n,i,p,j,m; while(~scanf("%d",&n)) { int a[1010][1010]; int b[1001]; scanf("%d",&m); for(i=1;i<=m;i++) { for(j=i;j<=m;j++) { scanf("%d",&a[i][j]); } } b[0]=0; for(i=1;i<=m;i++) { b[i]=100000000;//先给它赋一个大值之后再比较 for(j=0;j<i;j++) { b[i]=min(b[i],b[j]+n+a[j+1][i]);//先算前面的最小花费再到后面 } } printf("%d\n",b[m]); } return 0;}
- ZCMU-1404-Computers
- Computers
- Simple Computers
- ELECTRONIC COMPUTERS
- Simple Computers
- Computers zoj
- poj3486 Computers
- Quantum Computers
- Student Use of Computers
- How Computers Boot Up
- HDU 1913 Computers
- HDU 1913 Computers
- hdu acm 1913 Computers
- poj 2410 Simple Computers
- How Computers Boot Up
- 英语练习95 Computers
- How Computers Boot Up
- hdu 1913 computers
- iOS开发 UITest的使用
- Android 满屏隐藏虚拟键盘
- angular js Filter
- 二层三层转发学习
- JS判断客户端是否是iOS或者Android手机移动端
- ZCMU-1404-Computers
- Hadoop 入门
- 将博客搬至CSDN
- 回家过年要花多少钱?算完感觉生无可恋~
- 虚假的网络钓鱼攻击利用伪造的附件窃取Gmail凭据
- Ubuntu 启动activemq 报/data/activemq.pid: Permission denied 信息
- JVM学习之:调优总结 -Xms -Xmx -Xmn -Xss
- MongoDB_8天学通MongoDB——第三天 细说高级操作
- HTML转PDF工具(wkhtmltopdf)介绍,支持widows和linux