Gone Fishing

John is going on a fishing trip. He has h hours available, and there are n lakes in the area all reachable along a single, one-way road. John starts at lake 1, but he can finish at any lake he wants. He can only travel from one lake to the next one, but he does not have to stop at any lake unless he wishes to. For each i (1 to n-1), the number of 5-minute intervals it takes to travel from lake i to lake i+1 is denoted ti. For example, t3=4 means that it takes 20 minutes to travel from lake 3 to 4.

To help plan his fishing trip, John has gathered some information about the lakes. For each lake i, the number of fish expected to be caught in the initial 5 minutes, denoted fi, is known. Each 5 minutes of fishing decreases the number of fish expected to be caught in the next 5-minute interval by a constant rate of di. If the number of fish expected to be caught in an interval is less than or equal to di, there will be no more fish left in the lake in the next interval. To simplify the planning, John assumes that no one else will be fishing at the lakes to affect the number of fish he expects to catch. Write a program to help John plan his fishing trip to maximize the number of fish expected to be caught. The number of minutes spent at each lake must be a multiple of 5.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing two integers n (2 ≤ n ≤ 25) and h (1 ≤ h ≤ 16). Next, there is a line of n integers specifying fi (0 ≤ fi ≤ 1000), then a line of n integers di (0 ≤ di ≤1000), and finally, a line of n-1 integers denoting ti (0 < ti < 192).

Output

For each test case, print the case number first. Then print the number of minutes spent at each lake, separated by commas, for the plan achieving the maximum number of fish expected to be caught. This is followed by a line containing the number of fish expected. If multiple plans exist, choose the one that spends as long as possible at lake 1. If there is still a tie, choose the one that spends as long as possible at lake 2, and so on.

Sample Input

3

2 1

10 1

2 5

2

4 4

10 15 20 17

0 3 4 3

1 2 3

4 4

10 15 50 30

0 3 4 3

1 2 3

Sample Output

Case 1:

45, 5

Number of fish expected: 31

Case 2:

240, 0, 0, 0

Number of fish expected: 480

Case 3:

115, 10, 50, 35

Number of fish expected: 724

好奇怪的题

看上去像是背包,后来发现似乎时间不够

然后发现可以枚举停在哪里,然后用堆维护在1到k钓鱼的时候怎么钓

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void write(LL a)
{
if (a<){printf("-");a=-a;}
if (a>=)write(a/);
putchar(a%+'');
}
inline void writeln(LL a){write(a);printf("\n");}
int n,m,ans,len;
int v[],w[],t[];
int f[];
int sv[];
int wk[];
priority_queue<pa,vector<pa>,greater<pa> >q;
inline void solve(int k)
{
while (!q.empty())q.pop();
memset(wk,,sizeof(wk));
for (int i=;i<=k;i++)q.push(mkp(-v[i],i));
int rest=m-t[k],sum=;
if (rest<=)return;
while (rest&&!q.empty())
{
int v=-q.top().first,id=q.top().second;
//printf("q %d %d\n",v,id);
q.pop();
sum+=v;
wk[id]++;
if (v>w[id])q.push(mkp(-(v-w[id]),id));else q.push(mkp(,id));
rest--;
}
if (sum>ans){len=k;ans=sum;for (int i=;i<=n;i++)sv[i]=wk[i];return;}
if (sum<ans)return;
bool mrk=;
for (int i=;i<=k;i++)
{
if (wk[i]>sv[i])mrk=;
if (wk[i]!=sv[i])break;
}
if (mrk){len=k;ans=sum;for (int i=;i<=n;i++)sv[i]=wk[i];return;}
return;
}
inline void work(int cur)
{
n=read();m=read()*;
memset(sv,,sizeof(sv));
ans=;
for (int i=;i<=n;i++)v[i]=read();
for (int i=;i<=n;i++)w[i]=read();
for (int i=;i<=n;i++)t[i]=read()+t[i-];
for (int i=;i<=n;i++)solve(i);
printf("Case %d:\n",cur);
for (int i=;i<n;i++)printf("%d, ",*sv[i]);
printf("%d\n",*sv[n]);
printf("Number of fish expected: %d\n",ans);
}
int main()
{
int T=read(),tt=;while (T--)work(++tt);
}

LightOJ 1106

LightOJ1106 Gone Fishing的更多相关文章

  1. ZOJ 1015 Fishing Net(弦图判定)

    In a highly modernized fishing village, inhabitants there make a living on fishery. Their major tool ...

  2. bzoj 1242: Zju1015 Fishing Net 弦图判定

    1242: Zju1015 Fishing Net弦图判定 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 214  Solved: 81[Submit ...

  3. Poj/OpenJudge 1042 Gone Fishing

    1.链接地址: http://bailian.openjudge.cn/practice/1042/ http://poj.org/problem?id=1042 2.题目: Gone Fishing ...

  4. POJ 1042 Gone Fishing (贪心)(刘汝佳黑书)

    Gone Fishing Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 30281   Accepted: 9124 Des ...

  5. uva757 - Gone Fishing(馋)

    题目:uva757 - Gone Fishing(贪心) 题目大意:有N个湖泊仅仅有一条通路将这些湖泊相连. 每一个湖泊都会给最開始5分钟间隔内能够调到的鱼(f).然后给每过5分钟降低的鱼的数量(d) ...

  6. ●BZOJ 1006 [HNOI2008]神奇的国度(弦图最小染色数)○ZOJ 1015 Fishing Net

    ●赘述题目 给出一张弦图,求其最小染色数. ●题解 网上的唯一“文献”:<弦图与区间图>(cdq),可以学习学习.(有的看不懂) 摘录几个解决改题所需的知识点: ●子图和诱导子图(一定要弄 ...

  7. Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent

    Cocos2d-X开发教程-捕鱼达人 Cocos2-x development tutorial - fishing talent 作者:韩梦飞沙 Author:han_meng_fei_sha 邮箱 ...

  8. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

  9. Gone Fishing(贪心)

    Gone Fishing John is going on a fising trip. He has h hours available (1 ≤ h ≤ 16), and there are n ...

随机推荐

  1. ZOJ 3537 Cake (区间DP,三角形剖分)

    题意: 给出平面直角坐标系上的n个点的坐标,表示一个多边形蛋糕,先判断是否是凸多边形,若否,输出"I can't cut.".若是,则对这个蛋糕进行3角形剖分,切n-3次变成n-2 ...

  2. 通过StringBuilder的reverse()实现倒序

    import java.util.Scanner; public class ReverseString { public static void main(String[] args) { Scan ...

  3. JAVA初级必须要搞懂的事项(希望对新手有所帮助)

    1        安装JDK=> (1,下载JDK,安装,一般目录为C:\Program Files\Java中:2,通过Dos命令测试JDK是否安装=>java –version命令查看 ...

  4. 【原创】最有效解决IE8 position兼容性问题

    看了网上的的帖子真是水的一塌糊涂,完全没有解决我和广大网友们的关于ie8下position兼容性问题. 网上有的技术我就不说了 ,大家自行搜索,我想说的重点是 ie8不支持html5的新标签.这是重点 ...

  5. MAC 安装汇编编译工具 NASM

    直接运行nasm报错: 开始安装: brew reinstall nasm

  6. 在Phonegap下实现oAuth认证

    原文:http://www.kuqin.com/mobile/20120719/322873.html 前段时间做过两次关于Phonegap的现场交流会议分享.基本上把Phonegap的一些特性和大家 ...

  7. c++ 结构体,设置物品体积并输出物品属性

    #include <iostream> using namespace std; struct box { char maker[40]; float height; float widt ...

  8. MySQL中数组的存储

    1. MySQL中以字符串的形式存储数组 MySQL中无数组类型,通常将数组元素按某个字符分割以字符串形式存储 1.1. 求数组中元素的个数 方法:按指定符号分割字符串,返回分割后的元素个数.方法很简 ...

  9. 如何用纯 CSS 创作一个蝴蝶标本展示框

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/xzgZzQ 可交互视频教 ...

  10. Perl学习三:运算符

    运算符: 1.operand operator expression statement2.算术运算符 + - * / ** % -字符串参加运算必须转化为整数,若不能转化认为是0. 2.算术比较 & ...