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