Hdu2452 Navy maneuvers memory-based search

Source: Internet
Author: User

What does this question mean? I 've been reading for half a year, and it's messy.

The memory-based search is dragging. DP [I] [0] indicates the starting point of the ship with the minimum value as the target, DP [I] [1] indicates that the starting point of the ship whose maximum value is obtained is "I", and the starting point of the violent enumeration entry is "0", and the memory-based search is started,


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;}


Hdu2452 Navy maneuvers memory-based search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.