标签:des style blog class code c
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 32768/32768 K
(Java/Others)
Total Submission(s): 1507 Accepted
Submission(s): 520
赛后再贴 ^_^
先贴上超时的DFS代码:
1 #include <iostream>
2 #include <stdio.h>
3 #include <string.h>
4 using namespace std;
5 int Max;
6 int a[110][110];
7 bool isv[110][110];
8 int dx[3] = {1,-1,0};
9 int dy[3] = {0,0,1};
10 int m,n;
11 bool judge(int x,int y)
12 {
13 if(x<1 || x>m || y<1 || y>n)
14 return true;
15 if(isv[x][y])
16 return true;
17 return false;
18 }
19 void dfs(int x,int y,int money)
20 {
21 if(x==1 && y==n){
22 if(money>Max)
23 Max=money;
24 }
25 int i;
26 for(i=0;i<3;i++){
27 int nx = x+dx[i];
28 int ny = y+dy[i];
29 if(judge(nx,ny))
30 continue;
31 //可以走
32 isv[nx][ny] = true;
33 dfs(nx,ny,money+a[nx][ny]);
34 isv[nx][ny] = false;
35 }
36 }
37 int main()
38 {
39 int i,j,Case,T;
40 scanf("%d",&T);
41 for(Case=1;Case<=T;Case++){
42 scanf("%d%d",&m,&n);
43 for(i=1;i<=m;i++)
44 for(j=1;j<=n;j++)
45 scanf("%d",&a[i][j]);
46 printf("Case #%d:\n",Case);
47 Max=0;
48 memset(isv,0,sizeof(isv));
49 isv[1][1] = true;
50 dfs(1,1,a[1][1]);
51 printf("%d\n",Max);
52 }
53 return 0;
54 }
2014百度之星资格赛 1004:Labyrinth(DP),布布扣,bubuko.com
2014百度之星资格赛 1004:Labyrinth(DP)
标签:des style blog class code c
原文地址:http://www.cnblogs.com/yym2013/p/3733921.html