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

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>
            蜜月aⅴ免费一区二区三区| 国产日韩欧美中文| 校园春色综合网| 国产日韩精品在线观看| 国产麻豆午夜三级精品| 久久久久成人网| 中文在线一区| 国产精品成人在线观看| 亚洲第一在线| 日韩一级精品| 性欧美xxxx大乳国产app| 欧美成人午夜剧场免费观看| 日韩午夜精品视频| 欧美韩国一区| 欧美日韩在线视频首页| 久久精品一区二区三区中文字幕| 亚洲美女性视频| 日韩午夜激情| 国产精品一区一区| 久久精品99无色码中文字幕| 亚洲免费黄色| 激情视频一区二区| 欧美日韩在线三级| 久久青草欧美一区二区三区| 夜夜夜精品看看| 亚洲精品一二三| 免费亚洲一区二区| 久久免费99精品久久久久久| 亚洲图片激情小说| 亚洲自拍电影| 亚洲综合视频一区| 亚洲女人天堂av| 亚洲激情成人| 亚洲视频第一页| 欧美在线黄色| 9l国产精品久久久久麻豆| 久久久久九九九| 亚洲人成在线观看一区二区| 欧美11—12娇小xxxx| 一区二区三区视频免费在线观看| 久久精视频免费在线久久完整在线看| 欧美另类视频在线| 国产亚洲精品成人av久久ww| 欧美三级午夜理伦三级中视频| 久久精品人人| 一区二区三区国产盗摄| 久久免费视频一区| 亚洲视频在线一区| 国产一区二区电影在线观看 | 欧美三级网址| 亚洲美女免费视频| 久久成人精品无人区| 国产一区在线视频| 毛片av中文字幕一区二区| 巨乳诱惑日韩免费av| 亚洲自拍偷拍视频| 欧美在线free| 亚洲视频www| 亚洲国产婷婷| 亚洲高清不卡一区| 亚洲精品一区二区网址| 91久久久久| 亚洲欧美另类综合偷拍| 国产精品中文字幕欧美| 欧美jizz19性欧美| 国产精品一区二区女厕厕| 久久久精品tv| 亚洲日本中文字幕区| 亚洲人成网站999久久久综合 | 欧美极品欧美精品欧美视频| 久久免费一区| 欧美成人激情视频| 久久久美女艺术照精彩视频福利播放| 美女在线一区二区| 在线视频你懂得一区| 久久五月婷婷丁香社区| 国产精品国产自产拍高清av| 伊人久久亚洲影院| 亚洲欧美变态国产另类| 欧美激情视频一区二区三区在线播放 | 欧美激情久久久久久| 先锋资源久久| 亚洲一区二区三区视频| 欧美日韩国产三级| 日韩亚洲一区二区| 欧美一区国产二区| 女女同性女同一区二区三区91| 欧美国产日韩一区二区三区| 91久久在线播放| 一区二区三区不卡视频在线观看 | 欧美日本中文| 久久全国免费视频| 欧美日韩中文字幕综合视频| 久久九九电影| 欧美在线观看网站| 亚洲国产mv| 亚洲欧美bt| 性刺激综合网| 久久全国免费视频| 欧美超级免费视 在线| 亚洲午夜在线观看| 亚洲精品欧洲精品| 欧美一区二区视频免费观看| 欧美日韩国产精品成人| 这里只有精品视频| 一区二区三区日韩欧美| 国产精品欧美经典| 麻豆精品在线观看| 欧美成人一品| 亚洲欧洲av一区二区| 久久精品国产在热久久 | 亚洲黄色免费网站| 久久综合九色欧美综合狠狠| 一区二区三区在线免费观看| 最近看过的日韩成人| 欧美性做爰毛片| 欧美日韩福利| 亚洲视频欧美在线| 欧美不卡一区| 亚洲影院在线| 国产精品一区二区三区四区| 亚洲三级国产| 亚洲三级免费| 欧美日韩四区| 亚洲精品一区二区三区四区高清 | 久久久久久自在自线| 亚洲第一福利视频| 久久精品一本| 激情偷拍久久| 91久久国产精品91久久性色| 欧美精品久久久久久久久久| 亚洲一区国产精品| 午夜精品成人在线| 一区二区av在线| 国产精品第三页| 亚洲影院色在线观看免费| 日韩午夜电影| 亚洲国产免费| 国产精品国产三级国产aⅴ无密码| 亚洲精品影视在线观看| 久久久久久亚洲精品杨幂换脸| 影音先锋欧美精品| 亚洲国产一区二区a毛片| 免费日韩av电影| 日韩视频久久| 欧美激情久久久| 欧美一区二区三区在线| 国产精品v欧美精品v日韩| 亚洲国产成人在线播放| 亚洲欧洲日产国产网站| 你懂的视频一区二区| 欧美二区在线观看| 日韩亚洲欧美在线观看| 国产精品每日更新| 欧美伊人久久久久久午夜久久久久 | 亚洲图片在线观看| 久久国产66| 久热精品视频在线观看一区| 亚洲国产高清高潮精品美女| 久久久夜夜夜| 一区二区国产精品| 午夜精品一区二区三区在线视 | 欧美激情中文不卡| 亚洲精品自在久久| 国产精品女人毛片| 久久综合电影| 亚洲一区国产视频| 一本色道久久综合亚洲精品不卡| 午夜精品久久久久久久久久久| 国产真实久久| 欧美精品久久99| 久久电影一区| 亚洲欧美成aⅴ人在线观看| 性欧美暴力猛交69hd| 国产精品99久久久久久久久| 国产精品夜色7777狼人| 久久夜色精品亚洲噜噜国产mv| 亚洲高清视频一区二区| 亚洲女性裸体视频| 国产亚洲成av人片在线观看桃| 欧美岛国激情| 午夜精品久久久久久久99水蜜桃| 久久久久久久久一区二区| 在线看一区二区| 欧美日韩国产成人在线免费| 久久国产手机看片| 亚洲精品一区二区三区四区高清| 国产免费成人| 欧美精品九九| 欧美日韩国产二区| 久久综合久色欧美综合狠狠| 亚洲欧美日韩国产中文| 久久成人av少妇免费| 欧美精品亚洲精品| 国产欧美一区二区三区沐欲 | 99精品免费视频| 久久久精品动漫| 国产一区二区三区观看| 亚洲午夜91| 亚洲韩日在线|