青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

superman

聚精會神搞建設 一心一意謀發(fā)展
posts - 190, comments - 17, trackbacks - 0, articles - 0
   :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

ZOJ 1102 - Phylogenetic Trees Inherited

Posted on 2008-04-06 11:13 superman 閱讀(443) 評論(0)  編輯 收藏 引用 所屬分類: ZOJ

Official Solution:

Problem G: Phylogenetic Trees Inherited

The first thing to observe is that the different positions in every sequence are independent of each other. This reduces the tree of sequences to a tree of amino acids. At the root of the tree, or for that matter of any sub-tree, there may be many possible amino acids leading to optimal costs. Suppose, you have calculated for two sub-trees Tl and Tr the sets of amino-acids leading to optimal costs Al and Ar. Adjacent sub-trees Tl and Tr have as their father the node T. Now you want to find the set of amino-acids A that you can mark T with, leading to optimal costs for T.

There are two cases: if the intersection of Al with Ar is non-empty, define A as just this intersection, otherwise define A to be the union of Al and Ar. To see why this is true, observe the extra costs you get, when you assemble T from Tl and Tr. In the first case, you have 0 extra costs when you take an amino-acid from the intersection, but 1 or 2 extra costs when you do not. In the second case, you have 1 extra costs when you take an amino-acid from the union, but 2 extra-costs when you do not. Now, you may want to assemble T not from Tl and Tr but from some other sub-optimal trees. As you can easily verify, this leads to sub-optimal costs for T as well.

This reasoning is carried over straightforwardly to an induction proof and leads to a dynamic programming solution. Since the amino-acids are upper-case letters, you can represent sets of amino-acids as ints. The set operations you need are then easily performed as bitwise and respectively or. Whenever you do a union operation, your costs increase by 1.

Another, more straight-forward solution is to calculate for each node of the tree the optimal costs for every amino acid the node can be marked with. This is done by trying every possible combination of amino acids for the two sub-trees, assuming their optimal costs have already been calculated. Since this solution might turn out to be too inefficient, it can be improved upon by observing that a father node always can be marked with either the left or the right son's amino-acid - there is no need to take an amino acid that differs from both.

Judges' test data was constructed from a test-case with a few long sequences, a test-case with many short sequences, a test-case where every possible pair of amino-acids occured, and 100 random-generated test-cases where length and number of sequences are geometrically distributed. The total number of test-cases is 110. Since there may be multiple correct answers for the test cases, a special verification program was written by slightly modifying the judges' solution.


 1 /* Accepted 1102 C++ 00:00.56 1040K */
 2 #include <string>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n, l;
10     while((cin >> n >> l) && n && l)
11     {
12         int heap[2048], cost = 0;
13         string seq[1024];
14         
15         for(int i = 0; i < n; i++)
16             cin >> seq[i];
17         
18         for(int i = 0; i < l; i++)
19         {
20             for(int k = 0; k < n; k++)
21                 heap[n + k] = 1 << (seq[k][i] - 'A');
22             for(int k = n - 1; k >= 1; k--)
23                 if((heap[k] = heap[2 * k] & heap[2 * k + 1]) == 0)
24                 {
25                     cost++;
26                     heap[k] = heap[2 * k] | heap[2 * k + 1];
27                 }
28             char c = 'A';
29             while(heap[1>>= 1)
30                 c++;
31             cout << c;
32         }
33         cout << ' ' << cost << endl;
34     }
35     
36     return 0;
37 }
38 
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品在线一区二区| 亚洲一区二区三区精品在线| 久久久久国内| 亚洲春色另类小说| 欧美激情一区二区三区不卡| 免费成人高清视频| 日韩午夜三级在线| 日韩午夜av| 国产伦精品一区二区三区免费迷 | 国产欧美精品日韩精品| 久久久久久电影| 久久夜色精品国产| 一本色道久久加勒比精品| 亚洲美女毛片| 国产女主播一区二区三区| 久久亚洲春色中文字幕久久久| 老司机67194精品线观看| 亚洲欧洲在线视频| 亚洲一区视频| 亚洲第一视频网站| 亚洲深夜激情| 国内精品亚洲| 亚洲精品免费一二三区| 欧美三级日韩三级国产三级| 欧美在线观看网址综合| 欧美成人精品在线播放| 亚洲一区在线观看视频| 久久免费99精品久久久久久| 一区二区激情小说| 久久精品亚洲一区二区三区浴池| 亚洲精品国产精品国产自| 亚洲男女自偷自拍| 日韩一级二级三级| 欧美亚洲一区| 亚洲图色在线| 久久午夜国产精品| 性一交一乱一区二区洋洋av| 欧美本精品男人aⅴ天堂| 欧美一区二区三区在线观看视频| 美女国内精品自产拍在线播放| 亚洲欧美激情在线视频| 欧美aaaaaaaa牛牛影院| 久久精品国产综合| 国产精品福利久久久| 亚洲国产成人精品女人久久久 | 国产一区二区中文| 日韩一级黄色av| 亚洲国产精品一区制服丝袜| 亚洲免费网址| 亚洲图片欧美午夜| 亚洲欧洲日产国码二区| 激情综合色丁香一区二区| 亚洲国产精品久久久| 国产日韩在线视频| 一区二区成人精品| 夜夜精品视频一区二区| 欧美电影美腿模特1979在线看| 久久久久国产一区二区| 国产美女精品视频| 亚洲影院色无极综合| 亚洲一区二区三区四区中文 | 久久久免费av| 久久久一本精品99久久精品66| 国产精品成人一区二区网站软件| 亚洲国产精品欧美一二99| 在线欧美亚洲| 久久久久久久久岛国免费| 欧美一乱一性一交一视频| 国产精品久久久久久久久久久久久久 | 亚洲片国产一区一级在线观看| 久久精品欧美日韩精品| 老牛嫩草一区二区三区日本| 国内精品一区二区三区| 久久国产毛片| 欧美jizzhd精品欧美喷水 | 国产精品久久国产精品99gif| 日韩视频在线观看国产| 这里只有精品视频在线| 欧美婷婷久久| 亚洲欧美激情四射在线日 | 久久人人看视频| 亚洲国产高清自拍| 99视频在线观看一区三区| 欧美日韩一区在线播放| 中文亚洲视频在线| 久久精品一区二区三区四区| 狠狠色丁香婷婷综合久久片| 久久久久久夜| 亚洲激情网站| 午夜精品一区二区三区电影天堂| 国产色爱av资源综合区| 久久深夜福利| 一本色道久久综合亚洲精品婷婷 | 日韩视频在线一区| 欧美视频中文一区二区三区在线观看 | 久久精品亚洲国产奇米99| 欧美成人国产一区二区| 在线亚洲激情| 国产在线视频欧美| 欧美日韩国产综合久久| 久久av一区| 亚洲美女诱惑| 麻豆精品精品国产自在97香蕉| 亚洲作爱视频| 激情久久久久久久久久久久久久久久| 欧美国产成人在线| 先锋影院在线亚洲| 亚洲精品中文字| 免费成人你懂的| 亚洲一区二区在线播放| 在线观看日韩av| 国产精品久久7| 欧美高清视频www夜色资源网| 亚洲永久精品大片| 亚洲精品一区在线| 久久综合久久久| 亚洲主播在线观看| 亚洲三级观看| 在线欧美日韩| 国产日韩欧美一区二区三区在线观看| 欧美成人精品| 久久综合福利| 久久国产一区| 欧美一级免费视频| 亚洲视频精品| 日韩视频在线一区二区| 欧美成人激情视频| 久久综合九色欧美综合狠狠| 亚洲欧美日韩人成在线播放| 一区二区高清视频| 亚洲精品一区中文| 亚洲第一天堂无码专区| 国产揄拍国内精品对白| 国产欧美大片| 国产精品一区二区在线观看不卡 | 欧美日韩国产免费| 麻豆成人精品| 蜜臀av性久久久久蜜臀aⅴ四虎| 午夜精品区一区二区三| 宅男精品视频| 亚洲一区二区黄| 一区二区三区精密机械公司| 亚洲美女色禁图| 99精品欧美一区二区三区综合在线| 亚洲电影第1页| 欧美激情在线免费观看| 欧美肥婆在线| 亚洲国产精品尤物yw在线观看| 免费欧美网站| 亚洲高清av| 亚洲精品影院在线观看| 日韩亚洲视频| 亚洲视频在线一区| 午夜国产欧美理论在线播放| 亚洲欧美中文日韩在线| 欧美一级播放| 久久精品视频在线免费观看| 久久人人97超碰精品888| 老司机免费视频一区二区| 蜜桃久久av| 欧美丝袜一区二区三区| 国产精品视频免费观看www| 国产欧美日本一区二区三区| 国产亚洲欧美在线| 在线色欧美三级视频| 亚洲人午夜精品| 亚洲免费一区二区| 久久一区亚洲| 亚洲精品乱码久久久久| 亚洲神马久久| 久久综合影音| 欧美日韩国产在线播放网站| 国产精品一区二区三区观看| 在线精品视频一区二区| 亚洲美女av在线播放| 性做久久久久久久免费看| 麻豆精品视频在线观看| 日韩亚洲欧美中文三级| 久久精品99| 欧美日韩一区二区在线观看视频| 国产欧美日韩在线播放| 亚洲激情视频在线| 午夜精品电影| 亚洲电影免费观看高清完整版在线观看 | 雨宫琴音一区二区在线| 亚洲精品一区二区网址| 欧美一级大片在线免费观看| 乱人伦精品视频在线观看| 日韩午夜免费视频| 欧美在线视频一区二区| 欧美精品一区二区三区蜜桃| 国产视频久久久久久久| 日韩一区二区精品| 久久偷看各类wc女厕嘘嘘偷窃| 亚洲精品欧洲| 老牛嫩草一区二区三区日本 | 久久激五月天综合精品| 欧美三区美女| 亚洲人成毛片在线播放| 久久久xxx|