Chinaunix首页 | 论坛 | 博客
  • 博客访问: 114501
  • 博文数量: 23
  • 博客积分: 975
  • 博客等级: 准尉
  • 技术积分: 262
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-19 00:54
文章分类
文章存档

2011年(2)

2010年(3)

2008年(18)

我的朋友

分类:

2008-07-19 02:39:26

Problem G:Gone Fishing

Time Limit:1000MS  Memory Limit:65536K
Total Submit:21 Accepted:6

Language: not limited

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.

Sample Input

2 
1
10 1
2 5
2
4
4
10 15 50 30
0 3 4 3
1 2 3
0

Sample Output

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



解:


#include<stdio.h>
#include <malloc.h>

int findMax(int fi[],int i)
{
    int j,max=0;

    for(j=0;j<=i;j++) if(fi[j]>fi[max]) max=j;
    return max;
}

int plan(int n,int h,int fi[],int di[],int ti[],int si[])
{
    int intervalNum,tempFi[25],tempSi[25][25],i,j,k,count,max=-1,maxP;

    for(i=0;i<n;i++)
    {
        count=0;
        for(j=0;j<=i;j++)
        {
            tempFi[j]=fi[j];
            tempSi[i][j]=0;
        }
        intervalNum=h*12;
        for(j=0;j<i;j++) intervalNum-=ti[j];
        while(intervalNum>0)
        {
            k=findMax(tempFi,i);
            count+=tempFi[k];
            tempFi[k]=tempFi[k]>=di[k]?tempFi[k]-di[k]:0;
            tempSi[i][k]++;
            intervalNum--;
        }
        if(count>max)
        {
            max=count;
            maxP=i;
        }
    }
    for(j=0;j<=maxP;j++) si[j]=tempSi[maxP][j];
    for(;j<n;j++) si[j]=0;
    return max;
}

void main()
{
    typedef struct forcache
    {
        int n,h,fi[25],di[25],ti[24],si[25],max;
        struct forcache *next;
    }cache;
    cache *head,*p,*q;
    int m,i;
    head=p=(cache *)malloc(sizeof(cache));
    head->next=NULL;

    while(1)
    {
        scanf("%d",&m);
        if(m)
        {
            q=(cache *)malloc(sizeof(cache));
            q->next=NULL;
            p->next=q;
            p=p->next;
            p->n=m;
        }
        else break;
        scanf("%d",&p->h);
        for(i=0;i<p->n;i++) scanf("%d",&p->fi[i]);
        for(i=0;i<p->n;i++) scanf("%d",&p->di[i]);
        for(i=0;i<p->n-1;i++) scanf("%d",&p->ti[i]);
        for(i=0;i<p->n;i++) p->si[i]=0;
        p->max=plan(p->n,p->h,p->fi,p->di,p->ti,p->si);
    }
    p=head->next;
    while(p)
    {
        for(i=0;i<p->n;i++)
        {
            printf("%d",p->si[i]*5);
            if(i!=p->n-1) printf(", ");
            else printf("\nNumber of fish expected: %d\n\n",p->max);
        }
        p=p->next;
    }
}

阅读(978) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~