所以我们在算他在1到n个池塘钓鱼的情况是,先把路上的时间减完。然后每次都取能钓到的鱼最多的池塘钓,这样到最后一定是钓得最多的鱼。
#include <cstdio> #include <cstring> using namespace std; const int INF = 0x3f3f3f3f; const int N = 26; // f 为每个鱼塘初始的鱼,d为每5分钟减少的鱼,t为i-1,到i所花费的时间 struct Node { int f,d,t; }node[N],out[N],copy[N]; int t[N]; int n,h; int main() { int cas = 0; while(scanf("%d",&n) != EOF && n) { memset(node,0,sizeof(node)); scanf("%d",&h); for(int i = 0; i < n; i++) { scanf("%d",&node[i].f); } for(int i = 0; i < n; i++) { scanf("%d",&node[i].d); } int tmp; t[0] = 0; for(int i = 1; i < n; i++) { scanf("%d",&tmp); t[i] = t[i-1] + tmp; } int max = -INF; int max_x,max_v; for(int i = 0; i < n; i++) { int sum = 0, time = h*12; time -= t[i]; //减去路程剩余的时间 memcpy(copy,node,sizeof(node)); while(time > 0) { max_x = max_v = 0; for(int j = 0; j <= i; j++) { if(max_x < copy[j].f) { max_x = copy[j].f; max_v = j; } } copy[max_v].t += 1; sum += copy[max_v].f; if(copy[max_v].f - copy[max_v].d >= 0) { copy[max_v].f -= copy[max_v].d; }else { copy[max_v].f = 0; } time--; } if(max < sum) { max = sum; memcpy(out,copy,sizeof(out)); } } if(cas++) { printf("\n"); } for(int i = 0; i < n; i++) { printf("%d",out[i].t*5); if(i != n-1) { printf(", "); } } printf("\n"); printf("Number of fish expected: %d\n",max); } return 0; }