1.链接地址:

http://bailian.openjudge.cn/practice/1042/

http://poj.org/problem?id=1042

2.题目:

Gone Fishing
Time Limit: 2000MS   Memory Limit: 32768K
Total Submissions: 27652   Accepted: 8199

Description

John is going on a fishing trip. He has h hours available (1 <= h <= 16), and there are n lakes in the area (2 <= n <= 25) 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,...,n - 1, the number of 5-minute intervals it takes to travel from lake i to lake i + 1 is denoted ti (0 < ti <=192). For example, t3 = 4 means that it takes 20 minutes to travel from lake 3 to lake 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( fi >= 0 ), 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 (di >= 0). 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

You
will be given a number of cases in the input. Each case starts with a
line containing n. This is followed by a line containing h. Next, there
is a line of n integers specifying fi (1 <= i <=n), then a line of
n integers di (1 <=i <=n), and finally, a line of n - 1 integers
ti (1 <=i <=n - 1). Input is terminated by a case in which n = 0.

Output

For
each test case, 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 (you should print the entire plan on one line even
if it exceeds 80 characters). 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, even if no fish are expected to be caught in some
intervals. If there is still a tie, choose the one that spends as long
as possible at lake 2, and so on. Insert a blank line between cases.

Sample Input

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
0

Sample Output

45, 5
Number of fish expected: 31 240, 0, 0, 0
Number of fish expected: 480 115, 10, 50, 35
Number of fish expected: 724

Source

3.思路:

DP

4.代码:

 //2010-04-22
//v0.1 create by wuzhihui
#include<iostream>
using namespace std; int ti[];//ti (0 < ti <=192
int fi[];
int fi2[];
int di[];
int a[];
int maxa[];
int main()
{
int i,j;
int h,h2;//hour between 1<=h<=16
int n;//lake 2 <= n <= 25
int fishes;
int maxfishes,temp;
int max;
while((cin>>n)&&n!=)
{
cin>>h;
for(i=;i<n;i++) cin>>fi[i];
for(i=;i<n;i++) cin>>di[i];
for(i=;i<n-;i++) cin>>ti[i];
max=-;
for(j=;j<n;j++) a[j]=;
for(i=;i<n;i++)
{
h2=h*;
//memset(a,0,sizeof(a));
for(j=;j<n;j++) a[j]=;
fishes=;
for(j=;j<n;j++) fi2[j]=fi[j];
for(j=;j<=i-;j++) h2-=ti[j];
while(h2>)
{
maxfishes=-;
for(j=;j<=i;j++)
{
if(fi2[j]>maxfishes)
{
maxfishes=fi2[j];
temp=j;
}//if
}//for_j
fishes+=maxfishes;
a[temp]++;
if(fi2[temp]<di[temp]) fi2[temp]=;
else fi2[temp]-=di[temp];
h2--;
}//while_h2
if(max<fishes)
{
max=fishes;
for(j=;j<n;j++) maxa[j]=a[j];
}//if
}//while_n
cout<<(maxa[]*);
for(i=;i<n;i++) cout<<", "<<(maxa[i]*);
cout<<endl;
cout<<"Number of fish expected: "<<max<<endl<<endl;
} return ;
}

Poj/OpenJudge 1042 Gone Fishing的更多相关文章

  1. POJ #1042 Gone Fishing - WA by a DP solution. TODO

    I used DP instead of Greedy. But got WA on PoJ, though it passed all web-searched cases. Maybe I hav ...

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

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

  3. poj -- 1042 Gone Fishing(枚举+贪心)

    题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...

  4. POJ 1042 Gone Fishing

    题意:一个人要在n个湖中钓鱼,湖之间的路径是单向的,只能走1->2->3->...->n这一条线路,告诉你每个湖中一开始能钓到鱼的初始值,和每钓5分钟就减少的数量,以及湖之间的 ...

  5. POJ 1042 Gone Fishing#贪心

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cstring> using namespace std ...

  6. POJ 1042 Gone Fishing( DP )

    题意:小明打算做一个h((1 <= h <= 16))个小时钓鱼旅行.发现这里有n(2 <= n <= 25)个湖,而且所有的湖都在一条路的旁边.小明打算从第1个湖开始钓起,每 ...

  7. Poj OpenJudge 百练 1062 昂贵的聘礼

    1.Link: http://poj.org/problem?id=1062 http://bailian.openjudge.cn/practice/1062/ 2.Content: 昂贵的聘礼 T ...

  8. Poj OpenJudge 百练 1860 Currency Exchang

    1.Link: http://poj.org/problem?id=1860 http://bailian.openjudge.cn/practice/1860 2.Content: Currency ...

  9. Poj OpenJudge 百练 2602 Superlong sums

    1.Link: http://poj.org/problem?id=2602 http://bailian.openjudge.cn/practice/2602/ 2.Content: Superlo ...

随机推荐

  1. iOS开发——新特性OC篇&Objective新特性

    Objective新特性 Overview 自 WWDC 2015 推出和开源 Swift 2.0 后,大家对 Swift 的热情又一次高涨起来,在羡慕创业公司的朋友们大谈 Swift 新特性的同时, ...

  2. JavaScript学习总结-技巧、有用函数、简洁方法、编程细节

    整理JavaScript方面的一些技巧.比較有用的函数,常见功能实现方法,仅作參考 变量转换 //edit http://www.lai18.com var myVar = "3.14159 ...

  3. REM 注释

    REM 是DOS批处理和VB的注释语句.所谓注释语句,就是程序的执行时会跳过该行(不管它后面写的什么),它为编程者起到一个批注的功能,以达到好的可读性以便于交流以及起到备忘作用. 在批处理命令中如果不 ...

  4. linux实例 批量修改图片文件名

    1.如10.11一批这样的目录,10.11 10.12等等 然后里面的图片.jpg文件要修改成对应的日期.jpg,也就是说 编程1011.jpg这样的文件名 示例如下: #!/bin/bashfor ...

  5. 简洁判断一个byte中有多少位为1的bit?

    以下是Brian W. Kernighan公开的一个方法 unsigned bit_count(unsigned v) { unsigned int c; //置位总数累计 ; v; c++) { v ...

  6. Asp.Net 之 缓存机制

    asp.net缓存有三种:页面缓存,数据源缓存,数据缓存. 一.页面缓存 原理:页面缓存是最常用的缓存方式,原理是用户第一次访问的时候asp.net服务器把动态生成的页面存到内存里,之后一段时间再有用 ...

  7. Android(java)学习笔记135:Android中assets文件夹资源的访问

    Android资源文件分类: Android资源文件大致可以分为两种: 第一种是res目录下存放的可编译的资源文件: 这种资源文件系统会在R.java里面自动生成该资源文件的ID,所以访问这种资源文件 ...

  8. 会话状态Session解析以及原理分析

    我们知道web网站在客户端存储数据有三种形式:1. Cookie   2. hidden(隐藏域) 3.QueryString 其中viewstate什么的都是通过第二种方式隐藏域存储滴. 客户端存储 ...

  9. linux 多核

    posix threading programming beej's guide to unix ipc the gnu c library: virtual memory allocation an ...

  10. [转].net连oracle的问题及方法折腾总结 连接字串

    本文转自:http://www.th7.cn/Program/net/201305/138265.shtml 对oracle不算熟,对.net结合oracle开发项目也只做过一个.最近换了新电脑,装了 ...