# ZOJ 1107FatMouse and Cheese (BFS)

Source: Internet
Author: User

Analysis: A graph of n * N, each point is a cheese volume, starting from 0, 0 each time up to the K-step, the next volume must be greater than the previous step, to find the maximum volume and

`1#include <iostream>2#include <cstdio>3#include <queue>4#include <cstring>5#include <algorithm>6 using namespacestd;7 Const intMax =550+Ten;8 Const intINF =0x3f3f3f3f;9 intG[max][max], Dp[max][max];Ten intN, K; One intgx[4] = {0,0,1, -1}; A intgy[4] = {1, -1,0,0}; - structNode - { the     intx, y; -  - }; - voidBFsintXinty) + { - node node; +node.x =x; ANode.y =y; atDp[x][y] =G[x][y]; -Queue<node>que; - Que.push (node); -     intMAXN =-INF; -      while(!que.empty ()) -     { innode =Que.front (); - Que.pop (); to         if(Dp[node.x][node.y] >MAXN) +MAXN =Dp[node.x][node.y]; -          for(inti =0; I <4; i++) the         { *              for(intj =1; J <= K; J + +) \$             {Panax Notoginseng                 intFX = node.x + gx[i] *J; -                 intFY = node.y + gy[i] *J; the                 if(FX >=1&& FY >=1&& FX <= n && fy <= n && g[fx][fy] >G[node.x][node.y]) +                 { A                     if(Dp[fx][fy] < G[fx][fy] +Dp[node.x][node.y]) the                     { +DP[FX][FY] = G[fx][fy] +Dp[node.x][node.y]; - Node temp; \$temp.x =FX; \$TEMP.Y =fy; - Que.push (temp); -                     } the                 } -             }Wuyi         } the     } -printf"%d\n", MAXN); Wu } - intMain () About { \$      while(SCANF ("%d%d", &n, &k)! =EOF) -     { -         if(n = =-1&& k = =-1) -              Break; A          for(inti =1; I <= N; i++) +              for(intj =1; J <= N; J + +) thescanf"%d", &g[i][j]); -Memset (DP,0,sizeof(DP)); \$BFs1,1); the     } the     return 0; the}`
View Code

ZOJ 1107FatMouse and Cheese (BFS)

Related Keywords:

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.