poj 1949 Chores

题意是有N行任务,给出完成每项任务所需要的时间长度,求出完成所有任务所需要的最短时间.每个任务都会有一个约束条件,就是在完成这项任务之前必须完成所列出的其它任务.可以同时做多项任务.简单来说就像煮饭炒菜问题一样,可以一边烧饭一边炒菜.但炒菜之前必先洗菜.

不要想太复杂了,杂活i所需要的时间是本身的时间加上完成前提杂活的最晚时间。完成杂活的总时间就是各个杂活完成的最大时间。

#include<stdio.h>
#include<string.h>
int n,time,pre,num,ans,maxn;
int dp[20005];                  
int  main(){
    while(scanf("%d",&n)!=EOF)
    {
       ans=-1;
       memset(dp,0,sizeof(dp));
       for(int i=1;i<=n;i++)
       {
           maxn=0;
           scanf("%d%d",&time,&pre);
           for(int j=1;j<=pre;j++)
           {
             scanf("%d",&num);
             if(dp[num]>maxn)
                maxn=dp[num];
           }
           dp[i]= maxn+time;
           if(dp[i]>ans)
             ans=dp[i];
       }
       printf("%d\n",ans);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Description Farmer John's family pitches in with the chores during milking, doing all the chores as quickly as possible. At FJ's house, some chores cannot be started until others have been completed, e.g., it is impossible to wash the cows until they are in the stalls. Farmer John has a list of N (3 <= N <= 10,000) chores that must be completed. Each chore requires an integer time (1 <= length of time <= 100) to complete and there may be other chores that must be completed before this chore is started. We will call these prerequisite chores. At least one chore has no prerequisite: the very first one, number 1. Farmer John's list of chores is nicely ordered, and chore K (K > 1) can have only chores 1,.K-1 as prerequisites. Write a program that reads a list of chores from 1 to N with associated times and all perquisite chores. Now calculate the shortest time it will take to complete all N chores. Of course, chores that do not depend on each other can be performed simultaneously. Input * Line 1: One integer, N * Lines 2..N+1: N lines, each with several space-separated integers. Line 2 contains chore 1; line 3 contains chore 2, and so on. Each line contains the length of time to complete the chore, the number of the prerequisites, Pi, (0 <= Pi <= 100), and the Pi prerequisites (range 1..N, of course). Output A single line with an integer which is the least amount of time required to perform all the chores. Sample Input 7 5 0 1 1 1 3 1 2 6 1 1 1 2 2 4 8 2 2 4 4 3 3 5 6 Sample Output 23 Hint [Here is one task schedule: Chore 1 starts at time 0, ends at time 5. Chore 2 starts at time 5, ends at time 6. Chore 3 starts at time 6, ends at time 9. Chore 4 starts at time 5, ends at time 11. Chore 5 starts at time 11, ends at time 12. Chore 6 starts at time 11, ends at time 19. Chore 7 starts at time 19, ends at time 23. ] Source USACO 2002 February
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值