Problem 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.
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.
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
19HintAn 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.
/*刚开始时没想通,老是绕着1-1,2-2.。。。。情况,其实可以一行行的看5+3,7+3,50+3只使用一台电脑的时候,第一年,第二年,第三年
使用两台的时候用使用一年的加即8+6+3,8+3+8第二年,第三年,与第一行的比较,如果较小就替换掉,不过时自己太粗心了,出现好多次WA
1,下标写错了,多1或少1.。。。。。2.输入错误了,第一个数据是c我却把他存到n*/
#include<stdio.h>
#include<string.h>
int year[10000];
int main()
{register int i,k;
int n,d,c,min;freopen("E://in.txt","r",stdin);
while(scanf("%d",&c)!=EOF)
{
scanf("%d",&n);
memset(year,0,sizeof(year));
for(i=0;i<n;i++)
{
scanf("%d",&year[i]);
year[i]=year[i]+c;
}
for(k=0;k<=n-2;k++)
for(i=k;i<n-1;i++)
{
scanf("%d",&d);
min=d+c+year[k];
if(min<year[i+1]) year[i+1]=min;
}
printf("%d/n",year[n-1]);
}
return 0;}