北大poj-1062

 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 43523 Accepted: 12760

Description

Input

Output

Sample Input

```1 4
10000 3 2
2 8000
3 5000
1000 2 1
4 200
3000 2 1
4 200
50 2 0
```

Sample Output

`5250分析：需要注意几点：　　人物等级限制；　　存在内环，如果没有用剪枝（一旦当前金额大于存储值，则剪枝）的话，需要判断；　　记得设定初始值为酋长的price；　　存在只换东西，不需要加钱的情况；结论：邻接矩阵+递归df。待解决问题：真的是筋疲力竭了，所有discuss里的测试数据全部通过，奈何.....还是WA啊，为毛....`
``` 1 #include <stdio.h>
2 #include <string.h>
3
4 #define MAXNUM 105
5 #define MAX 65535
6
7 int gwLevelgap;
8 int gwMax;
9 int gwTotal = MAX;
10 int gawRouteMap[MAXNUM][MAXNUM];
11 int gawLevel[MAXNUM];
12 int gawPrice[MAXNUM];
13 int gawRecord[MAXNUM];
14
15 void GetInput()
16 {
17     int i = 0;
18     int j = 0;
19     int wPrice = 0;
20     int wLevel = 0;
21     int wExcNum = 0;
22     int wNo = 0;
23     int wRoutePrice = 0;
24     scanf("%d %d", &gwLevelgap, &gwMax);
25     for(i=0; i<gwMax; i++)
26     {
27         scanf("%d %d %d", &wPrice, &wLevel, &wExcNum);
28         gawLevel[i] = wLevel;
29         gawPrice[i] = wPrice;
30         for(j=0; j<wExcNum; j++)
31         {
32             scanf("%d %d", &wNo, &wRoutePrice);
33             gawRouteMap[i][wNo-1] = wRoutePrice;
34         }
35     }
36 }
37
38 int CalcPrice(int j, int sum, int maxlevel, int minlevel)
39 {
40     int i = 0;
41     int all0flag = 1;
42     if(j > gwMax-1)
43         return 0;
44     if(gawRecord[j] == 1)
45     {
46         return 1;
47     }
48     gawRecord[j] = 1;
49     if(gawLevel[j] > maxlevel)
50         maxlevel = gawLevel[j];
51     if(gawLevel[j] < minlevel)
52         minlevel = gawLevel[j];
53     if(maxlevel - minlevel > gwLevelgap)
54     {
55         return 1;
56     }
57     for(i=0; i<gwMax; i++)
58     {
59         if(gawRouteMap[j][i] != -1)
60         {
61             if(1 == CalcPrice(i, sum+gawRouteMap[j][i], maxlevel, minlevel))
62                 if(sum + gawPrice[j] < gwTotal)
63                     gwTotal = sum + gawPrice[j];
64             if(j == 0)
65             {
66                 memset(gawRecord, 0, MAXNUM*sizeof(int));
67                 gawRecord[j] = 1;
68             }
69             all0flag = 0;
70         }
71     }
72     if(all0flag == 1)
73     {
74         sum += gawPrice[j];
75         if(sum < gwTotal)
76             gwTotal = sum;
77     }
78     return 0;
79 }
80
81 int main(void)
82 {
83     memset(gawRouteMap, -1, MAXNUM*MAXNUM*sizeof(int));
84     GetInput();
85     gwTotal = gawPrice[0];
86     CalcPrice(0, 0, gawLevel[0], gawLevel[0]);
87     printf("%d\n", gwTotal);
88
89     return 0;
90 }```

```1 3
10000 3 1
2 200
1000 2 2
1 100
3 400
50 2 0

650

1 5
10000 3 2
2 5000
3 5000
3000 4 1
4 400
3000 2 1
4 500
1000 3 1
5 100
100 2 0

5700

1 5
10000 3 2
2 5000
3 5000
3000 4 1
4 400
3000 2 1
4 500
1000 3 1
5 100
100 2 0

5700

1 5
10000 3 2
2 5000
3 5000
3000 2 1
4 500
3000 4 1
4 400
1000 3 1
5 100
100 2 0

5700

1 5
10000 3 1
2 1000
1000 2 2
3 400
4 500
1000 1 1
5 50
1000 2 1
5 100
50 2 0

1650

1 9
100 1 8
2 80
3 80
4 80
5 80
6 80
7 80
8 80
9 80
100 1 8
1 80
3 80
4 80
5 80
6 80
7 80
8 80
9 80
100 1 8
1 80
2 80
4 80
5 80
6 80
7 80
8 80
9 80
100 1 8
1 80
2 80
3 80
5 80
6 80
7 80
8 80
9 80
100 1 8
1 80
2 80
3 80
4 80
6 80
7 80
8 80
9 80
100 1 8
1 80
2 80
3 80
4 80
5 80
7 80
8 80
9 80
100 1 8
1 80
2 80
3 80
4 80
5 80
6 80
8 80
9 80
100 1 8
1 80
2 80
3 80
4 80
5 80
6 80
7 80
9 80
100 1 8
1 80
2 80
3 80
4 80
5 80
6 80
7 80
8 80

100```
```4 5
800 3 2
2 1
3 2
20 1 1
4 1
30 5 1
4 2
100 4 1
5 0
5 7 0

9```

原文作者：Online Judge POJ
原文地址: https://www.cnblogs.com/bixiongquan/p/5383888.html
本文转自网络文章，转载此文章仅为分享知识，如有侵权，请联系博主进行删除。