http://poj.org/problem?id=1949
一句话破题,“Farmer John's list of chores is nicely ordered, and chore K (K > 1) can have only chores 1,.K-1 as prerequisites.”
View Code
#include <iostream> using namespace std ; int dp[10001] ; int main() { int n ; while(~scanf("%d",&n)) { int w,k,maxx ; int ans=0 ; for(int i=1;i<=n;i++) { scanf("%d%d",&w,&k) ; maxx=0 ; while(k--) { int p ; scanf("%d",&p) ; maxx=max(maxx,dp[p]) ; } dp[i]=w+maxx ; ans=max(ans,dp[i]) ; } printf("%d\n",ans) ; } return 0 ; }