博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Computers 递推题 sum[i][j]=max(sum[i-1][i-1]+c+sum[i][j],sum[i-1][j]);
阅读量:6812 次
发布时间:2019-06-26

本文共 2119 字,大约阅读时间需要 7 分钟。

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

335 7 506 810

Sample Output

19 *********************************************************************************************************************************************************** 经典  ***********************************************************************************************************************************************************
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 int sum[1001][1001]; 8 int n,c,i,j,k; 9 int main()10 {11 while(scanf("%d",&c)!=EOF)12 {13 scanf("%d",&n);14 for(i=0;i
View Code

 

转载于:https://www.cnblogs.com/sdau--codeants/p/3364831.html

你可能感兴趣的文章
CSDN泄密统计
查看>>
我的友情链接
查看>>
redhat 生产环境版本选择
查看>>
第八章第二层交换和生成树协议(STP)
查看>>
ab 测试简单说明
查看>>
apache 伪静态转到nginx
查看>>
runtime
查看>>
我的友情链接
查看>>
LayoutInflater拦截View创建,自定义Resource对象
查看>>
Adobe CS6
查看>>
linux命令完整篇
查看>>
烂泥:apache虚拟主机的学习与应用
查看>>
C语言 整人程序“我是猪”
查看>>
简述MAC地址与IP地址的关系
查看>>
JAVA设计模式之单例模式
查看>>
java regex详解
查看>>
apache 目录认证
查看>>
ActiveMQ消息队列
查看>>
我的友情链接
查看>>
Java中堆内存和栈内存详解
查看>>