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

superman

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

ZOJ 1102 - Phylogenetic Trees Inherited

Posted on 2008-04-06 11:13 superman 閱讀(440) 評論(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片| 国产婷婷97碰碰久久人人蜜臀| 久久偷窥视频| 亚洲综合色自拍一区| 亚洲第一视频| 久久国产福利国产秒拍| 在线综合亚洲欧美在线视频| 国产精品99久久久久久www| 亚洲黄色性网站| 免费亚洲电影在线观看| 午夜精品久久久久久99热| 亚洲国产高清自拍| 国产一二精品视频| 亚洲国产一区二区三区a毛片| 国产视频自拍一区| 国产精品久久久久久亚洲毛片| 欧美激情精品久久久久久蜜臀| 久久成人免费日本黄色| 亚洲一区久久久| 一本色道久久综合亚洲精品不卡 | 欧美日本免费一区二区三区| 一区二区在线观看视频在线观看| 亚洲黄色精品| 在线播放日韩| 亚洲电影第三页| 伊人久久噜噜噜躁狠狠躁 | 亚洲激情第一区| 欧美成人情趣视频| 欧美刺激性大交免费视频| 国产区日韩欧美| 亚洲黄色一区| 一本色道久久综合亚洲二区三区| 亚洲精品老司机| 亚洲青色在线| 日韩亚洲欧美高清| 一区二区欧美视频| 日韩一二在线观看| 欧美一二三视频| 麻豆精品一区二区av白丝在线| 久久精品91久久久久久再现| 亚洲欧美中日韩| 黄色成人小视频| 一区二区三区四区五区视频| 久久综合99re88久久爱| 一区二区三区精品视频在线观看| 久久亚洲综合| 好吊色欧美一区二区三区四区 | 99精品99久久久久久宅男| 久久视频一区| 亚洲免费在线播放| 国产精品久久久久久福利一牛影视 | 男男成人高潮片免费网站| 亚洲欧美国产另类| 国产乱码精品一区二区三区不卡| 亚洲香蕉在线观看| 亚洲毛片在线免费观看| 欧美日本韩国| 亚洲天堂av在线免费| 亚洲三级电影全部在线观看高清 | 国产精品久久福利| 欧美亚洲在线观看| 午夜精品电影| 韩国精品久久久999| 久久免费视频一区| 日韩一级黄色av| 亚洲高清三级视频| 欧美福利一区二区| 亚洲图片激情小说| 一区二区三区四区五区视频| 欧美三级欧美一级| 欧美一区二区三区视频免费| 欧美一区国产一区| 一区二区视频免费完整版观看| 开心色5月久久精品| 免播放器亚洲一区| 在线天堂一区av电影| 亚洲综合丁香| 亚洲高清av| 一本久久知道综合久久| 国产农村妇女毛片精品久久麻豆 | 亚洲国产精品一区制服丝袜| 在线视频一区观看| 亚洲一区尤物| 亚洲电影观看| 日韩一级片网址| 国产欧美日韩视频在线观看 | 欧美一级在线播放| 91久久精品美女| 亚洲一区二区三区涩| 亚洲成人影音| 亚洲天堂男人| 亚洲国产一区二区在线| 亚洲免费综合| 亚洲国产综合在线| 亚洲男女毛片无遮挡| 亚洲免费成人av电影| 欧美一级淫片aaaaaaa视频| 妖精成人www高清在线观看| 性欧美超级视频| 亚洲作爱视频| 久久全国免费视频| 性伦欧美刺激片在线观看| 免费在线观看精品| 久久精品亚洲| 国产精品毛片va一区二区三区| 欧美 日韩 国产 一区| 国产精品欧美久久久久无广告| 嫩模写真一区二区三区三州| 国产精品久久午夜夜伦鲁鲁| 亚洲大胆视频| 国产亚洲一区二区三区| 中文一区二区| 亚洲午夜三级在线| 欧美福利一区二区| 欧美激情91| 精品成人免费| 欧美在线一二三| 亚洲一区二区三区午夜| 久久精品电影| 国产精品久久久久久亚洲毛片| 亚洲第一福利在线观看| 亚洲国产一区二区视频| 久久综合色一综合色88| 久久久久久久一区二区| 国产乱码精品1区2区3区| 在线亚洲国产精品网站| 在线一区二区三区四区五区| 免费视频一区二区三区在线观看| 久久久久se| 国内在线观看一区二区三区| 午夜免费电影一区在线观看| 午夜视频一区二区| 国产精品男人爽免费视频1| 99热在这里有精品免费| 一区二区三区高清视频在线观看| 欧美成人69av| 亚洲精品在线三区| 一区二区三区久久| 欧美日韩午夜视频在线观看| 999亚洲国产精| 亚洲欧美精品| 国产区精品视频| 久久―日本道色综合久久| 欧美成人精品三级在线观看 | 亚洲国产精品一区二区第四页av | 国产日韩欧美视频| 亚洲午夜精品久久久久久app| 国产精品99久久久久久久女警| 欧美日韩国产欧| 亚洲视频日本| 久久久久久网站| 91久久久久久| 国产精品mm| 久久精品毛片| 亚洲国产成人精品女人久久久 | 亚洲天堂av图片| 国产精品亚洲美女av网站| 欧美一区二区三区四区高清| 免费人成精品欧美精品| 亚洲精品系列| 国产精品久久亚洲7777| 久久国产精品高清| 91久久久一线二线三线品牌| 亚洲一区二区三区在线观看视频| 国产一区二区三区自拍| 欧美成人在线网站| 亚洲无亚洲人成网站77777| 久久人人精品| 亚洲小说欧美另类婷婷| 国色天香一区二区| 欧美精品日日鲁夜夜添| 欧美亚洲三区| 亚洲美女中出| 免费av成人在线| 午夜精品在线观看| 亚洲成人中文| 国产精品综合色区在线观看| 暖暖成人免费视频| 欧美在线高清| 亚洲综合电影一区二区三区| 亚洲电影成人| 欧美精品粉嫩高潮一区二区| 亚洲宅男天堂在线观看无病毒| 欧美激情精品久久久六区热门 | 国产女优一区| 欧美精品在欧美一区二区少妇| 亚洲一区二区三区精品在线| 欧美国产一区二区| 久久视频国产精品免费视频在线| 国产精品99久久99久久久二8| 亚洲狠狠婷婷| 狠狠网亚洲精品| 国产欧美在线视频|