Title Description Description
Adamyi's Windows 2013 timed out (--!), so he had to witness the movie scene in front of his own house. Although he did not want to miss this wonderful moment, his belly protested repeatedly and demanded that the Last supper be eaten first.
Now adamyi ready to eat N-dishes in turn. But he only use spoons and chopsticks to eat, spoons and chopsticks can be used alternately, but the same vegetables can only use a tableware, before dinner he took chopsticks. the time to eat the I course with a spoon and chopsticks is a_i and b_i respectively. The time for the chopsticks and the spoon to be exchanged is c_i before eating the I course.
Now tell Adamyi to finish the N-course meal according to his plan, the minimum time required.
Enter a description input
Description first line, a positive integer n (1<=n<=100)
The following n rows, respectively, are three positive integers a_i,b_i,c_i (1<=a_i,b_i,c_i<=10000)outputs description output
Description
A number, the shortest time
sample input to
sample
3
20 40 20
10 4 25
90 100 5
Sample output Sample outputs
139
A DP that compares water
use f[i,1] to indicate the minimum time to use the first I course when I eat with a spoon
use f[i,2] to indicate the minimum time to use the first I course when I eat with chopsticks
F[i,1]=min{f[i-1,1]+a[i],
F[i-1,2]+c[i]+a[i]}
F[i,2]=min{f[i-1,2]+b[i],
F[i-1,1]+c[i]+b[i]}
PS: This question is about getting chopsticks at the beginning.
So,f[1,1]=c[1]+a[1]
f[1,2]=b[1];
var f:array[1..100,1..2]of longint;
A,b,c:array[1..100]of Longint;
I,j,k:longint;
M,n:longint;function min (x,y:longint): Longint;
Begin IF X>y
Then Exit (y)
else exit (x);
End
begin READLN (n);
For i:=1 to n do
readln (A[i],b[i],c[i]);
F[1,1]:=a[1];
F[1,2]:=b[1];
For i:=2 to n do
For j:=1 to 2 do
begin F[i,1]:=min (F[i-1,1]+a[i],f[i-1,2]+c[i]+a[i]);
f[i,2]:=min (F[i-1,2]+b[i],f[i-1,1]+c[i]+b[i]);
end;
writeln (min (f[n,1],f[n,2]));
end.
Dp:windows 2013