枚举+贪心
在取钓鱼数最多的湖时候可以用优先队列
#include <iostream>
#include <algorithm>
using namespace std;
/*
#include <FSTREAM>
ifstream fin("data.txt");
#define cin fin
*/
int n, h, fi[26], ti[26], di[26];
int timepath[26][26];
int enumsum[26];
int enumlastlake(int lastlake)
{
int remain[26], unusedtime, i, maxfish, index, sum;
memcpy(remain, fi, sizeof(fi));
unusedtime = h;
for (i=1; i<=lastlake-1; i++)
unusedtime -= ti[i];
sum = 0;
while (unusedtime>=5)
{
maxfish = -1;
for (i=1; i<=lastlake; i++)
{
if (maxfish < remain[i])
{
maxfish = remain[i];
index = i;
}
}
if (maxfish == 0)
{
timepath[lastlake][1] += unusedtime;
break;
}
//在index这个湖钓鱼
sum += remain[index];
remain[index] -= di[index];
if (remain[index] < 0)
remain[index] = 0;
timepath[lastlake][index]+=5;
unusedtime -= 5;
}
enumsum[lastlake] = sum;
return sum;
}
int main()
{
int count, i, j, res, index, t;
cin >> count;
while (count--)
{
t = 1;
while (cin >> n && n)
{
cin >> h;
h = 60 * h;
for (i=1; i<=n; i++)
cin >> fi[i];
for (i=1; i<=n; i++)
cin >> di[i];
for (i=1; i<=n-1; i++)
{
cin >> ti[i];
ti[i] *= 5;
}
memset(timepath, 0, sizeof(timepath));
for (i=1; i<=n; i++)
{
enumlastlake(i);
}
for (res=-1, i=1; i<=n; i++)
{
if (res < enumsum[i])
{
res = enumsum[i];
index = i;
}
}
if (t!=1)
cout << endl;
t++;
for (i=1; i<=n; i++)
{
cout << timepath[index][i];
if (i<n)
cout << ", ";
}
cout << endl << "Number of fish expected: " << res << endl;;
}
if (count != 0)
cout << endl;
}
return 0;
}