zoukankan      html  css  js  c++  java
  • UPC10728:Imputation

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 31  解决: 12
    [提交] [状态] [命题人:admin]

    题目描述

    Leila is a Bioinformatician, interested in studying Bacterial evolution. In one experiment on a special type of Bacteria,she started from a single bacterium, put it on a plate, and monitored the bacterial division, until she obtained a population of k bacteria. During the process, she carefully reported the evolutionary relations between bacteria. Precisely, for each bacterium, she reported its parent bacterium.
    In the next step, she extracted DNA sequences of k bacteria in the final population, by NGS technology. Each DNA sequence is represented as a string of length m from the alphabet set { A, T, C, G }.
    The NGS technology has a drawback: it produces a lot of missing values. So, there are a lot of unknown characters indicated by ‘?’ in the extracted sequences. Considering the evolutionary relationship between bacteria, Leila wants to impute the missing values. Among all possible imputations, she wants to find the minimum cost imputation from an evolutionary perspective.
    The problem is defined as follows. A rooted tree T is given, and for each leaf v of T, a string b v of length m from the character set { A, T, C, G, ? } is given. A transition cost matrix ∆ is also given, where ∆(x, y) (x, y ∈ { A, T, C, G }) represents the cost of a transition from an x character to a y character, from a parent to its child.
    A feasible imputation, assigns a string s u of length m from the character set { A, T, C, G } to each vertex u, where for each leaf v of T, sv is equal to b v except for ‘?’ characters in bv . The evolutionary cost of an imputation is defined as the sum of evolutionary costs of all edges. The evolutionary cost of an edge between parent u and child w, is defined as , where su[i] is the i-th character of su.
    Leila wants to find a feasible imputation for T, which has the minimum evolutionary cost among all feasible imputations.
    The tree T, transition cost matrix ∆, and a string bv for each leaf v are given. You should write a program to compute the minimum evolutionary cost of feasible imputations.

    输入

    The first line of the input contains an integer n (2 ⩽ n ⩽ 10, 000) denoting the number of vertices of T. The vertices of T are numbered from 1 to n. The root of the tree is numbered 1. The root is never considered as a leaf, even if it has only one child. The next n − 1 lines describe the edges of T; each line contains two endpoints of an edge separated by spaces. 
    In the next four lines, the evolutionary cost matrix ∆ is given; each line is for one row of ∆. Rows (corresponding to a parent) and columns (corresponding to a child) of ∆ are ordered to respectively represent characters A, T, C and G. All entries of ∆ are non-negative integers not more than 106 . The next line just contains k, the number of leaves. Finally,each leaf v (its number) and its bv which is a string of size m (1 ⩽ m ⩽ 200) appear in one line.

    输出

    In one line, print the minimum evolutionary cost of feasible imputations.

    样例输入

    3
    1 2
    1 3
    0 3 4 4
    4 0 4 4
    4 4 2 4
    1 1 1 0
    2
    2 AAC
    3 T?C
    

    样例输出

    4
    #include "bits/stdc++.h"
     
    using namespace std;
    typedef long long ll;
    const int maxn = 1e4 + 100;
    vector<int> e[maxn];
    int delt[100][100];
    map<char, int> mp;
    char str[maxn][210];
    int vis[maxn], v[maxn];
    ll dp[maxn][10];
     
    void dfs(int now, int i) {
        v[now] = 1;
        if (vis[now]) {
            if (str[now][i] == '?') return;
     
            int k = mp[str[now][i]];
            for (int j = 1; j <= 4; j++) {
                if (j != k) dp[now][j] = 1e18;
            }
            return;
        }
        for (auto p:e[now]) {
            if (!v[p]) {
                dfs(p, i);
                for (int j = 1; j <= 4; j++) {
     
                    ll minn = 1e18;
                    for (int k = 1; k <= 4; k++) {
                        minn = min(minn, dp[p][k] + delt[j][k]);
                    }
                    dp[now][j] += minn;
                }
            }
        }
    }
     
    int main() {
        //freopen("input.txt", "r", stdin);
        mp['A'] = 1;
        mp['T'] = 2;
        mp['C'] = 3;
        mp['G'] = 4;
        int n;
        cin >> n;
        int x, y;
        for (int i = 1; i < n; i++) {
            cin >> x >> y;
            e[x].push_back(y);
            e[y].push_back(x);
        }
        for (int i = 1; i <= 4; i++) {
            for (int j = 1; j <= 4; j++) {
                cin >> delt[i][j];
            }
        }
        int k;
        cin >> k;
        for (int i = 0; i < k; i++) {
            cin >> x;
            cin >> str[x];
            vis[x] = 1;
        }
        ll ans = 0;
        int len = strlen(str[x]);
        for (int i = 0; i < len; i++) {
            memset(v, 0, sizeof(v));
            memset(dp, 0, sizeof(dp));
            dfs(1, i);
            ll minn = 1e18;
            for (int j = 1; j <= 4; j++) {
                minn = min(minn, dp[1][j]);
            }
            ans += minn;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    10. Regular Expression Matching
    Leetcode:9. Palindrome Number
    MySQL
    MyBatis Plus 自动类型转换之TypeHandler
    深拷贝和浅拷贝
    【强制】不要在程序中写死一年为 365 天,避免在公历闰年时出现日期转换错误或程序逻辑 错误。
    【强制】日期格式化时,传入 pattern 中表示年份统一使用小写的 y。
    【推荐】循环体内,字符串的连接方式,使用 StringBuilder 的 append 方法进行扩展。
    【强制】POJO如果继承了另一个 POJO 类,注意在前面加一下 super.toString。
    【强制】禁止使用构造方法 BigDecimal(double)的方式把 double 值转化为 BigDecimal 对象。
  • 原文地址:https://www.cnblogs.com/albert-biu/p/10689940.html
Copyright © 2011-2022 走看看