zoukankan      html  css  js  c++  java
  • Poj/OpenJudge 1042 Gone Fishing

    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.代码:

     1 //2010-04-22
     2 //v0.1 create by wuzhihui
     3 #include<iostream>
     4 using namespace std;
     5 
     6 int ti[194];//ti (0 < ti <=192
     7 int fi[194];
     8 int fi2[194];
     9 int di[194];
    10 int a[194];
    11 int maxa[194];
    12 int main()
    13 {
    14     int i,j;
    15     int h,h2;//hour between 1<=h<=16
    16     int n;//lake 2 <= n <= 25
    17     int fishes;
    18     int maxfishes,temp;
    19     int max;
    20     while((cin>>n)&&n!=0)
    21     {
    22         cin>>h;
    23         for(i=0;i<n;i++) cin>>fi[i];
    24         for(i=0;i<n;i++) cin>>di[i];
    25         for(i=0;i<n-1;i++) cin>>ti[i];
    26         max=-1;
    27         for(j=0;j<n;j++) a[j]=0;
    28         for(i=0;i<n;i++)
    29         {
    30             h2=h*12;
    31             //memset(a,0,sizeof(a));
    32             for(j=0;j<n;j++) a[j]=0;
    33             fishes=0;
    34             for(j=0;j<n;j++) fi2[j]=fi[j];
    35             for(j=0;j<=i-1;j++) h2-=ti[j];
    36             while(h2>0)
    37             {
    38                 maxfishes=-1;
    39                 for(j=0;j<=i;j++)
    40                 {
    41                     if(fi2[j]>maxfishes)
    42                     {
    43                         maxfishes=fi2[j];
    44                         temp=j;
    45                     }//if
    46                 }//for_j
    47                 fishes+=maxfishes;
    48                 a[temp]++;
    49                 if(fi2[temp]<di[temp]) fi2[temp]=0;
    50                 else fi2[temp]-=di[temp];
    51                 h2--;
    52             }//while_h2
    53             if(max<fishes)
    54             {
    55                 max=fishes;
    56                 for(j=0;j<n;j++) maxa[j]=a[j];
    57             }//if
    58         }//while_n
    59         cout<<(maxa[0]*5);
    60         for(i=1;i<n;i++) cout<<", "<<(maxa[i]*5);
    61         cout<<endl;
    62         cout<<"Number of fish expected: "<<max<<endl<<endl;
    63     }
    64     
    65 
    66     return 1;
    67 }
  • 相关阅读:
    程序=算法+数据结构 的理解
    为什么有些语言可以被反编译?而有的不能?
    手机怎么访问电脑服务器上的网页
    linux一键安装
    Linux初学者必知的5个学习网站
    忘记阿里云管理终端密码怎么办
    Linux学习(CentOS-7)---磁盘分区(概念、分区方法、分区方案)
    远程桌面怎样复制本地文件听语音
    如何查看某个端口被谁占用
    cmd命令
  • 原文地址:https://www.cnblogs.com/mobileliker/p/3546631.html
Copyright © 2011-2022 走看看