标签:os ar for on amp size as dp return
这题目意思能忍?读了半年,乱七八糟的
记忆化搜索 拖拖的,dp[i][0]代表以获得最小值为目标的船以i为起点,dp[i][1]代表以获得最大值为目标的船以i为起点,接下来暴力枚举入度为0的点为起点,开始记忆化搜索,
const int N = 100000 + 55; int dp[N][2]; int value[N]; int degree[N]; vector<int> G[N]; int n,m,f; void init() { memset(dp,-1,sizeof(dp)); memset(value,0,sizeof(value)); memset(degree,0,sizeof(degree)); for(int i=0;i<N;i++)G[i].clear(); } bool input() { while(cin>>n>>m>>f) { for(int i=1;i<=n;i++)scanf("%d",&value[i]); int q = m; while(q--) { int u,v; scanf("%d %d",&u,&v); G[u].push_back(v); degree[v]++; } return false; } return true; } int dfs(int pos,int mark) { if(dp[pos][mark&1] != -1)return dp[pos][mark&1]; if(G[pos].size() == 0)return dp[pos][mark&1] = value[pos]; dp[pos][mark&1] = 0; int maxn = -1,minn = inf; for(int i=0;i<G[pos].size();i++) { int v = G[pos][i]; if(mark&1)maxn = max(maxn,dfs(v,mark + 1)); else minn = min(minn,dfs(v,mark + 1)); } int tmp = (mark&1)?maxn:minn; return dp[pos][mark&1] = value[pos] + tmp; } void cal() { int ans = -1; for(int i=1;i<=n;i++) { if(degree[i] == 0) ans = max(ans,dfs(i,1)); } if(ans < f)puts("Glory"); else puts("Victory"); } void output() { } int main() { while(true) { init(); if(input())return 0; cal(); output(); } return 0; }
标签:os ar for on amp size as dp return
原文地址:http://blog.csdn.net/yitiaodacaidog/article/details/40024101