## Output

 1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 #include <cstring>
5 #include <queue>
6 #define rep(i,l,r) for(int i=l; i<=r; i++)
7 #define clr(x,y) memset(x,y,sizeof(x))
8 #define travel(x) for(Edge *p=last[x]; p; p=p->pre)
9 using namespace std;
10 const int INF = 0x3f3f3f3f;
11 const int maxn = 25;
13     int ans = 0, f = 1;
14     char c = getchar();
15     for(; !isdigit(c); c = getchar())
16     if (c == '-') f = -1;
17     for(; isdigit(c); c = getchar())
18     ans = ans * 10 + c - '0';
19     return ans * f;
20 }
21 int n,m,P,K,x,y,e,z,D,d[maxn],cost[110][110],dp[110];
22 bool blocked[maxn][110],invalid[maxn];
23 struct Edge{
24     Edge *pre;
25     int to,cost;
26 }edge[10010];
27 Edge *last[maxn],*pt = edge;
28 struct Node{
29     int x,d;
30     Node(int _x,int _d) : x(_x), d(_d){}
31     inline bool operator < (const Node &_Tp) const {
32         return d > _Tp.d;
33     }
34 };
35 priority_queue <Node> q;
36 inline void addedge(int x,int y,int z){
37     pt->pre = last[x]; pt->to = y; pt->cost = z; last[x] = pt++;
38 }
39 void dijkstra(){
40     clr(d,INF); d[1] = 0; q.push(Node(1,0));
41     while (!q.empty()){
42         Node now = q.top(); q.pop();
43         if (d[now.x] != now.d) continue;
44         travel(now.x){
45             if (invalid[p->to]) continue;
46             if (d[p->to] > d[now.x] + p->cost){
47                 d[p->to] = d[now.x] + p->cost;
48                 q.push(Node(p->to,d[p->to]));
49             }
50         }
51     }
52 }
53 int main(){
55     rep(i,1,e){
58     }
60     rep(i,1,D){
62         rep(j,x,y) blocked[P][j] = 1;
63     }
64     clr(cost,INF);
65     rep(i,1,n){
66         rep(j,i,n){
67             clr(invalid,0);
68             rep(k,2,m-1) rep(l,i,j)
69             if (blocked[k][l]) invalid[k] = 1;
70             dijkstra();
71             if (d[m] < INF) cost[i][j] = d[m] * (j-i+1);
72         }
73     }
74     clr(dp,INF); dp[0] = 0;
75     rep(i,1,n) rep(j,0,i-1) dp[i] = min(dp[i],dp[j] + cost[j+1][i] + K);
76     printf("%d\n",dp[n] - K);
77     return 0;
78 }
View Code

posted on 2016-01-13 14:01  ACMICPC  阅读(301)  评论(0编辑  收藏  举报