Windows (Codevs 1695)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.