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. Python 学习日志9月20日

    9月20日 周三 多大年龄了,还活得像个小孩.——急什么,人生又不长. 你习惯了思考宇宙星辰,一百年真的不长,一生也就不那么长,许多人的价值观念你也就无法理解.同样,许多人也无法理解你的价值观念,感兴 ...

  2. 一条SQL语句在MySQL中是如何执行的

    概览 本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新是怎么完成的. 一.mysql架构分析 mysql主要分为Server层和存储 ...

  3. Open Cascade:AIS_InteractiveContext如何调用函数选择AIS对象

    AIS_InteractiveContext如何调用函数选择AIS对象 myAISContext->MoveTo(point.x, point.y, myView); myAISContext- ...

  4. CPP-基础:运算符重载详解

    1.运算符重载定义: C++中预定义的运算符的操作对象只能是基本数据类型.但实际上,对于许多用户自定义类型(例如类),也需要类似的运算操作.这时就必须在C++中重新定义这些运算符,赋予已有运算符新的功 ...

  5. 线程调度的问题:Lock Convoy(锁封护)与Priority Inversion(优先级反转)

    Lock Convoy(锁封护) [1]Lock Convoy是在多线程并发环境下由于锁的使用而引起的性能退化问题.当多个相同优先级的线程频繁地争抢同一个锁时可能会引起lock convoy问题,一般 ...

  6. 欧拉函数φ(x)简要介绍及c++实现

    我还是很喜欢数论,从此吃喝不问,就此沉沦. 欧拉函数φ(x)的值为在[1,x)的区间内与x互质的数的个数 通式:    其中p1, p2……pn为x的所有质因数,x是不为0的整数.φ(1)=1. 注意 ...

  7. OJ 大整数减法

    描述 求两个大的正整数相减的差. 输入 共2行,第1行是被减数a,第2行是减数b(a > b).每个大整数不超过200位,不会有多余的前导零. 输出 一行,即所求的差. 样例输入 9999999 ...

  8. 【OS_Linux】三大文本处理工具之sed命令

    1.sed命令的简介及用法 sed:即为流编辑器,“stream editor”的缩写.他先将源文件读取到临时缓存区(也叫模式空间)中,再对满足匹配条件的各行执行sed命令.sed命令只针对缓存区中的 ...

  9. break、continue、exit、return的区别和对比

    break.continue.exit.return的区别和对比 一:说明 break.continue在条件循环语句及循环语句(for.while.if等)中用于控制程序的走向:而exit则用于种植 ...

  10. Python旅途——入门基础

    1.入门 ​ 作为近几年计算机程序设计语言中很火的Python,是一种面向对象的动态类型语言,最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的.大 ...