日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ 1949 Chores

發布時間:2024/10/8 编程问答 26 如意码农
生活随笔 收集整理的這篇文章主要介紹了 POJ 1949 Chores 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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.

]
題解:樹形DP入門題。從根節點往下依次更新出每一個節點的最短時間,則該最短時間的最大值即為:完成家務的最短時間。
參考代碼為:
#include <iostream>
#include <cstring>
using namespace std;
const int maxn=10005;
int c[maxn],n[maxn],dp[maxn]; int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int N,temp,sum=-maxn;
memset(dp,0,sizeof dp);
cin>>N;
for(int i=1;i<=N;i++)
{
cin>>c[i]>>n[i];
if(i==1) dp[i]=c[i];
else
{
int max=-maxn;
if(n[i]==0) dp[i]=c[i];
else
{
for(int j=0;j<n[i];j++)
{
cin>>temp;
if(dp[temp]>max) max=dp[temp];
}
dp[i]=max+c[i];
}
}
if(dp[i]>sum) sum=dp[i];
}
cout<<sum<<endl;
return 0;
} /*
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
*/

  

總結

以上是生活随笔為你收集整理的POJ 1949 Chores的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 长篇高h肉爽文丝袜 | 亲子伦视频一区二区三区 | 富婆如狼似虎找黑人老外 | 怡红院一区二区 | 天堂√8在线中文 | 中文字幕av一区 | 亚洲AV无码成人精品区明星换面 | 久草视频精品 | 老司机性视频 | 精品欧美一区二区久久久久 | 观看av免费| 国产不卡视频在线播放 | 国产精品久久久久久久久久久久久久 | 日韩二级片 | 中文字幕一二三四 | 国产精品久久综合视频 | 依依av| 国产成人精品av久久 | 日本精品在线观看视频 | 久久婷婷五月国产色综合激情 | 欧美国产一区二区 | 一区二区三区 中文字幕 | 国产一区二区在线电影 | 动漫av一区二区 | h狠狠躁死你h高h | 蜜臀少妇久久久久久久高潮 | 国产精品麻豆一区二区 | 在线视频www | 国产xxxx做受性欧美88 | 中文在线天堂网 | 亚洲一区二区三区中文字幕 | 清草视频 | 欧美午夜性生活 | 假日游船 | 影音先锋每日资源 | 免费精品久久 | 亚洲女同女同女同女同女同69 | 国产三级av在线 | 亚洲免费黄色网址 | 国产成人午夜精品无码区久久 | 一区二区播放 | 丝袜综合网 | 亚洲欧美另类在线观看 | 神马久久av | heyzo朝桐光一区二区 | 黑人极品ⅴideos精品欧美棵 | 无遮挡毛片 | 精品亚洲乱码一区二区 | 日本男女啪啪 | 中文字幕1页| 日韩欧美三级在线 | 成人wwwww免费观看 | 国产精品视频一 | 国产三级在线看 | 一级爱爱免费视频 | 亚洲伦理一区二区三区 | 国产精品欧美综合亚洲 | 日本内谢少妇xxxxx少交 | 亚洲国产欧美日韩 | 熟妇高潮一区二区三区在线播放 | 五月婷婷开心 | 午夜毛片电影 | 亚州av网| 亚洲国产精品成人综合久久久 | 日韩av网址在线观看 | 欧美一级生活片 | 国产精品乱码 | 少妇激情偷人三级 | 亚洲最大黄色 | 四虎精品久久 | 每日av在线 | 午夜久久久久久久久久影院 | 国产精品一区二区三 | 天天舔天天射 | 四虎免费在线观看 | 日美韩av| 在线不卡 | 国产高清欧美 | 色婷婷av一区二区三区软件 | 女人被狂躁c到高潮喷水电影 | 一区二区三区四区五区av | 亚洲欧美一区二区激情 | 伦理欧美 | 亚洲成人看片 | 99产精品成人啪免费网站 | 日韩一级片视频 | 国产福利片在线 | 欧美日韩一区电影 | 制服丝袜国产精品 | 中文字幕日韩久久 | 超碰五月天 | 日韩黄网| 日韩av网站大全 | 亚洲综合色在线观看 | 男女午夜爽爽爽 | 免费观看亚洲 | 国产激情免费视频 | 欧美在线观看一区二区三区 | 亚洲欧美色图片 |