编程介的小学生 2019-12-31 17:43 采纳率: 0.2%
浏览 75

Replica Placement 具体实现的思路

Problem Description
Topsky wants to build a content delivery network. It contains an origin server and some mirror servers as shown in figure 1. Original data is put at the origin server (root in figure 1) while replicas are put at some of the mirror servers (node 2 and 5 in figure 1). When a node issues a request of data, it will try to find its destination in following steps.
1. Check if there is a replica at its own place. If yes, the request meets. Otherwise do step 2.
2. Forward the request to its parent, and let its parent do step 1.

The cost of meeting the request C (v) is defined as the sum of weight of the edges along the road. If C (v) is not greater than an upper bound Q (v), then the retrieval cost is satisfied. Topsky further assumes a nonnegative cost S (v) which means the cost of storing data at node v. Note that the origin server is special, the cost of storing data at origin server is 0. Now Topsky wants to find the way of replicas placement such the retrieval cost of all nodes are satisfied while the total storage cost is minimal.

Input
The first line contains a single integer T (T <= 20), indicating the number of test cases.
Each case begins with three integers N (1<= N <= 1000) indicates the number of servers.
Then N lines follow. Each line contains four integers Fv (0 <= Fv <= N), Qv, Sv and Wv (0 <= Qv, Sv, Wv <= 105). In line i (1 <= i <= N), Fv is the father of node i (if Fv is 0, it means node i is the origin server, Qv is -1, Sv is 0 and Wv is 0), Qv is upper bound of retrieval cost, Sv is storing cost of node i and Wv is weight of this edge between node i and node Fv.

Output
For each test case, output the minimal storage cost in one line.

Sample Input
1
3
0 -1 0 0
1 1 1 1
2 1 1 1

Sample Output
1

  • 写回答

1条回答 默认 最新

  • 你知我知皆知 2024-07-27 11:38
    关注

    以下回答参考 皆我百晓生券券喵儿 等免费微信小程序相关内容作答,并由本人整理回复。

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 1e4 + 7;
    
    int n,m,k,d[20][maxn],s[maxn];
    struct edge{
        int to,next;
    }edge[maxn*2];
    
    void add(int x,int y){
        edge[++d[x]].to=y; edge[d[x]].next=d[y]; d[y]++;
    }
    
    int main(){
        scanf("%d",&m);
        for(int i=1;i<=m;++i)
            for(int j=1;j<=m;++j){
                scanf("%d",&k);
                s[i] += k;
            }
        for(int i=1;i<=m;++i)
            for(int j=i+1;j<=m;++j)
                add(i,j),add(j,i);
    
        memset(d,-1,sizeof d); 
        s[m]=0;
        priority_queue<int,vector<int>,greater<int>> q;
        q.push(0);
        while(q.size()){
            int now = q.top(); q.pop();
            if(now > m) continue;
            for(int i=1;i<=m;++i){
                if(d[now][i] == -1 || s[i]) continue;
                s[i]+=now;
                d[now][i] = i;
                q.push(s[i]);
            }
        }
    
        int ans = INT_MAX;
        for(int i=1;i<=m;++i)
            ans = min(ans,s[i]-s[i]+k);
        printf("%d\n",ans);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上