Bzoj 2072 POI2004 MOS dynamic programming + greedy

Source: Internet
Author: User

Problem: Bridge

We consider the use of the minimum time of two people its storing, the time of the large people sent to the past

There are two ways of doing this:

1. The person with the least time and the person who has the greatest time past, and then the least time person to bring the torch back

2. Time minimum and the second small two people past, then the time the youngest person to take the torch back, then the time is the largest and the second biggest two people in the past, time the second small person to take the torch back

In order to ensure that the optimal transport should be the two forms of

So f[i] that there is no bridge at the moment I have left the shortest time DP can

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 100100using namespace Std;int N,a[m];long long F[m];int Main () {int i;cin>>n;for (i=1;i<=n;i++) scanf ("%d", &a[i]), if (n<=2) return Cout<<a[n]<<endl,0;for (i=n-1;i>=2;i--) {f[i]=f[i+1]+a[1]+a[i+1];if (i <=n-2) F[i]=min (f[i],f[i+2]+a[2]+a[1]+a[i+2]+a[2]);} Cout<<f[2]+a[2]<<endl;return 0;}


Bzoj 2072 POI2004 MOS dynamic programming + greedy

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.