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 DescriptionFirst 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)
Output description
Output Description
A number, the shortest time
Sample input
Sample Input
3
20 40 20
10 4 25
90 100 5
Sample output
Sample Output
139
/*F[I][0/1] stands for Part I sub-dish with spoon or chopsticks*/#include<cstdio>#include<iostream>#defineM 110using namespacestd;intf[m][2],a[m],b[m],c[m],n;intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) scanf ("%d%d%d",&a[i],&b[i],&C[i]); f[1][0]=a[1]+c[1];f[1][1]=b[1]; for(intI=2; i<=n;i++) {f[i][0]=min (f[i-1][0]+a[i],f[i-1][1]+a[i]+C[i]); f[i][1]=min (f[i-1][1]+b[i],f[i-1][0]+b[i]+C[i]); } printf ("%d", Min (f[n][0],f[n][1])); return 0;}
View Code
Windows (Codevs 1695)