POJ1042 Gone Fishing
采用贪心策略。
假设他从1湖泊走到x 湖泊,这还剩下 h*12 - sigma(T1--Tx-1)。(单位时间为5分钟)。然后再用剩下的时间去钓1-x的湖泊的鱼。 每次都选择最多鱼的湖泊钓。
code:
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int maxn = 30; int f[maxn], tf[maxn], d[maxn], t[maxn], path[maxn]; int ans, p[maxn]; int main() { int h, n, i, j, k; while(scanf("%d",&n),n) { scanf("%d",&h); h *= 12; for(i=1; i<=n; ++i) scanf("%d",&f[i]); for(i=1; i<=n; ++i) scanf("%d",&d[i]); for(i=1; i<=n-1; i++) scanf("%d",&t[i+1]); for(i=2,t[1]=0; i<=n; ++i) t[i] += t[i-1]; ans = -1000; for(k=1; k<=n; ++k) if(h>t[k]) { int th = h - t[k]; int sum = 0; memset(path, 0, sizeof path ); for(i=1; i<=n; ++i) tf[i] = f[i]; while(th>0) { int maxx = 0; int mark = 0; for(i=1; i<=k; ++i) if(maxx<tf[i]) { maxx = tf[i]; mark = i; } if(!mark) break; sum += maxx; tf[mark] -= d[mark]; path[mark]++; th--; } path[1] += th; if(ans<sum) { ans = sum; for(j=1; j<=n; j++) p[j] = path[j]; } } for(i=1; i<n; ++i) printf("%d, ",p[i]*5); printf("%d\n",p[i]*5); printf("Number of fish expected: %d\n\n", ans); } return 0; }