问题 F: Imputation

时间限制: 1 Sec  内存限制: 128 MB
提交: 32  解决: 13
[提交] [状态] [命题人: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

[提交][状态]

应该是个树型dp

对每一个位置的字母分别dp寻找最小花费的结果

代码:

#include <bits/stdc++.h>typedef long long ll;
using namespace std;
const int maxn = 1e4 + 100;
const ll inf = 1e18;
vector<int> p[maxn];
int val[50][50];
char str[maxn][210];
int vis[maxn];
ll dp[maxn][10];
int s[maxn];
map<char, int> mp;void dfs(int x, int k) {s[x] = 1;if (vis[x]) {if (str[x][k] == '?') return;int a = mp[str[x][k]];for (int o = 1; o <= 4; o++) {if (o != a) dp[x][o] = inf;}}for (int y = 0; y < p[x].size(); y++) {if (!s[p[x][y]]) {dfs(p[x][y], k);for (int i = 1; i <= 4; i++) {ll minn = inf;for (int j = 1; j <= 4; j++) {minn = min(minn, dp[p[x][y]][j] + val[i][j]);}dp[x][i] += minn;}}}
}int main() {int n, u, v;scanf("%d", &n);for (int i = 1; i < n; i++) {scanf("%d%d", &u, &v);p[u].push_back(v);p[v].push_back(u);}for (int i = 1; i <= 4; i++) {for (int j = 1; j <= 4; j++)scanf("%d", &val[i][j]);}int q, l = -1;scanf("%d", &q);while (q--) {scanf("%d", &u);scanf("%s", str[u]);if (l == -1)l = strlen(str[u]);vis[u] = 1;}mp['A'] = 1;mp['T'] = 2;mp['C'] = 3;mp['G'] = 4;ll ans = 0;for (int i = 0; i < l; i++) {memset(dp, 0, sizeof(dp));memset(s, 0, sizeof(s));dfs(1, i);ll minn = inf;for (int j = 1; j <= 4; j++)minn = min(minn, dp[1][j]);ans += minn;}printf("%lld\n", ans);return 0;
}

UPC Imputation 树型dp相关推荐

  1. 其他OJ 树型DP 选课

    在朱全民的PPT介绍的一个树型DP经典题,<选课>,中文题目,不结束 找了很久找到了可以提交的OJ,重庆八中 http://www.cqoi.net:2012/JudgeOnline/pr ...

  2. 【树型DP】BZOJ1564 二叉查找树(noi2009)

    标签: 二叉查找树 [题目描述] 已知一棵特殊的二叉查找树.根据定义,该二叉查找树中每个结点的数据值都比它左儿子结点的数据值大,而比它右儿子结点的数据值小. 另一方面,这棵查找树中每个结点都有一个权值 ...

  3. 【树型DP】加分二叉树

    问题 b: [树型DP]加分二叉树 时间限制: 1 Sec  内存限制: 64 MB 提交: 8  解决: 6 [提交] [状态] [讨论版] [命题人:admin] 题目描述 科技忽略了过程就是魔法 ...

  4. 二叉苹果树(树型DP+背包)

    二叉苹果树 有一棵苹果树,如果树枝有分叉,一定是分2叉(就是说没有只有1个儿子的结点).这棵树共有N个结点(叶子点或者树枝分叉点),编号为1-N,树根编号一定是1. 我们用一根树枝两端连接的结点的编号 ...

  5. POJ3342 Party at Hali-Bula(树型DP求最大独立集+唯一解判断)

    题意: 公司参加聚会,要求员工不能和他的上司同时参加,求最多能参加几个人并且判断解是否唯一. 要点: 树型DP的经典题,用dp[u][1]表示选取u的最大值,dp[u][0]表示不选取u的最大值,容易 ...

  6. 虚树+树型DP SDOI2011消耗战

    <虚树+树型DP> SDOI2011消耗战 #include <iostream> #include <cstdio> #include <cstring&g ...

  7. BSOJ 2923:藤原妹红 MST+树型DP

    2923 -- [模拟试题]藤原妹红 Description 在幻想乡,藤原妹红是拥有不老不死能力的人类.虽然不喜欢与人们交流,妹红仍然保护着误入迷途竹林村民.由于妹红算得上是幻想乡最强的人类,对于她 ...

  8. 洛谷P3354 Riv河流 [IOI2005] 树型dp

    正解:树型dp 解题报告: 传送门! 简要题意:有棵树,每个节点有个权值w,要求选k个节点,最大化∑dis*w,其中如果某个节点到根的路径上选了别的节点,dis指的是到达那个节点的距离 首先这个一看就 ...

  9. hihocoder 1479 三等分 树型dp

    描述 小Hi最近参加了一场比赛,这场比赛中小Hi被要求将一棵树拆成3份,使得每一份中所有节点的权值和相等. 比赛结束后,小Hi发现虽然大家得到的树几乎一模一样,但是每个人的方法都有所不同.于是小Hi希 ...

  10. 蓝桥杯:生命之树【树型dp】

    之前本菜还没学树型dp的时候,下意识地认为这个东西很难,感觉这个东西结合了搜索+dp这两座算法界的大山必定很难,但万万没想到啊,这个东西很像我之前讲的记忆化搜索,甚至我认为,记忆化搜索的一个作用就是将 ...

最新文章

  1. 二十一、oracle pl/sql分类一 存储过程
  2. cocos2dx3.4 VS2012无法打开包含文件extensions/ExtensionExport.h
  3. Rust中对某个结构体实现方法于rust中的关联函数
  4. CodeForces - 594A Warrior and Archer(思维+博弈)
  5. http://127.0.0.1:8000/accounts/login/总是重定向到http://127.0.0.1:8000/accounts/profile/并且报告404
  6. CRM呼叫中心异步搜索实现的调试截图
  7. as3 java 交互_AS3常用代码(三):AS3与HTML的交互
  8. Java生产力提示:社区的热门选择
  9. 学习笔记(11月08日)--异常
  10. qt的项目中单个文件加载样式表
  11. java 声明抽象方法_java – 类必须声明为abstract或实现抽象方法错误
  12. 计算机网络学习(九)—应用层的概述
  13. php分类程序,PHP无限分类实现程序_PHP教程
  14. Fiddler中文使用教程-AutoResponder
  15. C++ QT学习之路----VS2017+QT环境搭建
  16. PKI加密体系加密过程及原理
  17. excel显著性检验_#如何用excel做anova分析#用excel做显著性分析
  18. SIM卡在手机中的主要作用
  19. python实现监控数据界面_python 监控界面
  20. EC20 HTTP 图片传输

热门文章

  1. php网站整合ck播放器,帝国cms整合CKplayer播放器代码教程
  2. 3D结构光摄像头深度算法
  3. tao.Opengl
  4. [terry笔记]Python字符串
  5. 数据结构与算法邓俊辉——(二)
  6. win10电脑任务栏突然卡死解决办法
  7. Scrapy-Redis使用教程将现有爬虫修改为分布式爬虫
  8. 调研目前主要的开源网络爬虫,并且说明各自的特点、局限性以及相互之间的区别
  9. java switch语句作用域,switch语句
  10. 读书笔记 摘自:《你坏》