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

coreBugZJ

此 blog 已棄。

Nuclear Fusion,Codeforces Beta Round #65 (Div. 2) ,E

E. Nuclear Fusion
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output



There is the following puzzle popular among nuclear physicists.

A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements.

You are allowed to take any two different atoms and fuse a new one from them. That results in a new atom, whose number is equal to the sum of the numbers of original atoms. The fusion operation can be performed several times.

The aim is getting a new pregiven set of k atoms.

The puzzle's difficulty is that it is only allowed to fuse two atoms into one, it is not allowed to split an atom into several atoms. You are suggested to try to solve the puzzle.



Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 17). The second line contains space-separated symbols of elements of n atoms, which are available from the start. The third line contains space-separated symbols of elements of k atoms which need to be the result of the fusion. The symbols of the elements coincide with the symbols from the periodic table of the chemical elements. The atomic numbers do not exceed 100 (elements possessing larger numbers are highly unstable). Some atoms can have identical numbers (that is, there can be several atoms of the same element). The sum of numbers of initial atoms is equal to the sum of numbers of the atoms that need to be synthesized.



Output

If it is impossible to synthesize the required atoms, print "NO" without the quotes. Otherwise, print on the first line «YES», and on the next k lines print the way of synthesizing each of k atoms as equations. Each equation has the following form: "x1+x2+...+xt->yi", where xj is the symbol of the element of some atom from the original set, and yi is the symbol of the element of some atom from the resulting set. Each atom from the input data should occur in the output data exactly one time. The order of summands in the equations, as well as the output order does not matter. If there are several solutions, print any of them. For a better understanding of the output format, see the samples.



Sample test(s)
Input
10 3
Mn Co Li Mg C P F Zn Sc K
Sn Pt Y
Output
YES
Mn+C+K->Sn
Co+Zn+Sc->Pt
Li+Mg+P+F->Y

Input
2 1
H H
He
Output
YES
H+H->He

Input
2 2
Bk Fm
Cf Es
Output
NO


Note

The reactions from the first example possess the following form (the atomic number is written below and to the left of the element):

To find a periodic table of the chemical elements, you may use your favorite search engine.

The pretest set contains each of the first 100 elements of the periodic table at least once. You can use that information to check for misprints.




學習了 fura2 的代碼——本來只是想偷懶拷貝一下元素表的,一不小心看到了代碼,于是。。。

因為學習了代碼,感覺思路還是挺簡單的,動態規劃。。

 1 #include <iostream>
 2 #include <cstring>
 3 #include <string>
 4 #include <map>
 5 
 6 using namespace std;
 7 
 8 const int N = 20;
 9 
10 int main() {
11         int n, n2, n21, k, i, j, s, t, nt;
12         static int sum[ 1<<N ], f[ 1<<N ], p[ 1<<N ];
13         string  nuclearA[ N ], nuclearB[ N ];
14         int numberA[ N ], numberB[ N ];
15 
16         map< stringint > number;
17         string nuclear[] = {
18                 "H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar",
19                 "K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br",
20                 "Kr","Rb","Sr","Y","Zr","Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te",
21                 "I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm",
22                 "Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl","Pb","Bi","Po","At","Rn",
23                 "Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm"
24         };
25         for ( i = 0; i < sizeof(nuclear)/sizeof(nuclear[0]); ++i ) {
26                 number[ nuclear[ i ] ] = i + 1;
27         }
28 
29         cin >> n >> k;
30         n2 = ( 1 << n );
31         n21 = n2 - 1;
32         for ( i = 0; i < n; ++i ) {
33                 cin >> nuclearA[ i ];
34                 numberA[ i ] = number[ nuclearA[ i ] ];
35         }
36         for ( i = 0; i < k; ++i ) {
37                 cin >> nuclearB[ i ];
38                 numberB[ i ] = number[ nuclearB[ i ] ];
39         }
40 
41         memset( sum, 0sizeof(sum) );
42         for ( s = 0; s < n2; ++s ) {
43                 for ( j = 0; j < n; ++j ) {
44                         if ( s & (1<<j) ) {
45                                 sum[ s ] += numberA[ j ];
46                         }
47                 }
48         }
49 
50         memset( f, -1sizeof(f) );
51         f[ 0 ] = 0;
52         for ( s = 0; s < n2; ++s ) {
53                 i = f[ s ];
54                 if ( (i==-1|| (i>=k) ) {
55                         continue;
56                 }
57                 t = (s^n21);
58                 for ( j = t; j >= 0--j ) {
59                         // nt = (j&t);  // 超時
60                         nt = j = (j&t);
61                         if ( sum[ nt ] == numberB[ i ] ) {
62                                 f[ nt | s ] = i + 1;
63                                 p[ nt | s ] = s;
64                         }
65                 }
66         }
67 
68         if ( f[ n21 ] < k ) {
69                 cout << "NO" << endl;
70         }
71         else {
72                 cout << "YES" << endl;
73                 s = n21;
74                 string str;
75                 while ( s > 0 ) {
76                         i = f[ s ] - 1;
77                         t = p[ s ];
78                         str = "";
79                         for ( j = 0; j < n; ++j ) {
80                                 if ( ((s&(1<<j))!=0&& ((t&(1<<j))==0) ) {
81                                         str += nuclearA[ j ];
82                                         str += "+";
83                                 }
84                         }
85                         str.erase( str.length()-1 );
86                         str += "->";
87                         str += nuclearB[ i ];
88                         cout << str << endl;
89                         s = t;
90                 }
91         }
92 
93         return 0;
94 }
95 

posted on 2011-03-31 19:55 coreBugZJ 閱讀(1535) 評論(1)  編輯 收藏 引用 所屬分類: ACM

Feedback

# re: Nuclear Fusion,Codeforces Beta Round #65 (Div. 2) ,E 2011-04-01 14:15 英雄哪里出來

來踩一下~~  回復  更多評論   


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产裸拍裸体视频在线观看乱了中文 | 中文精品视频| 99精品欧美一区| 欧美日韩国产一中文字不卡| 一区二区三区免费在线观看| 一区二区三区成人精品| 国产麻豆精品在线观看| 久久在线免费观看| 欧美另类一区二区三区| 欧美亚洲自偷自偷| 久久夜色精品国产欧美乱| 日韩亚洲欧美中文三级| 亚洲一区免费观看| 在线国产欧美| 一区二区三区免费看| 国产一区在线免费观看| 亚洲国产日韩一区| 欧美午夜精品一区| 免费日韩视频| 国产精品美女一区二区| 欧美凹凸一区二区三区视频| 欧美色综合天天久久综合精品| 欧美一进一出视频| 欧美久色视频| 久久综合久久综合久久| 欧美日韩亚洲综合在线| 美女视频黄a大片欧美| 国产精品av免费在线观看| 欧美成人免费网站| 国产日韩成人精品| 日韩亚洲综合在线| 国产综合精品一区| 日韩视频在线观看国产| 亚洲国产精品视频一区| 亚洲欧美一区二区原创| 一本久久青青| 欧美大色视频| 久久se精品一区精品二区| 日韩一级精品| 久久午夜电影网| 久久成人精品视频| 国产精品九九久久久久久久| 亚洲国产另类 国产精品国产免费| 国产精品青草综合久久久久99| 亚洲国产91| 亚洲国产合集| 久久久精品国产免费观看同学| 午夜精品久久久久久久蜜桃app | 久久久欧美精品sm网站| 欧美在线亚洲综合一区| 国产精品男人爽免费视频1 | 老司机精品导航| 国产一区在线播放| 欧美一区二区免费| 久久成人精品| 国产日产欧美a一级在线| 亚洲一区欧美一区| 性欧美长视频| 国产日韩精品一区二区三区| 亚洲一区欧美二区| 久久大逼视频| 国产综合色产在线精品| 久久精品一本| 欧美激情 亚洲a∨综合| 亚洲国产精品福利| 欧美国产精品一区| 亚洲精品综合精品自拍| 亚洲在线播放电影| 国产精品任我爽爆在线播放| 亚洲资源av| 久久九九热re6这里有精品| 国产一区激情| 蜜臀91精品一区二区三区| 91久久国产综合久久蜜月精品 | 亚洲欧洲偷拍精品| 中文av字幕一区| 国产伦精品一区二区| 欧美在线亚洲综合一区| 亚洲第一福利视频| 一区二区三区四区五区精品视频| 欧美日韩一区二区三区四区在线观看| 99亚洲一区二区| 久久国产精彩视频| 亚洲国产专区校园欧美| 欧美日韩久久不卡| 午夜伦欧美伦电影理论片| 欧美jjzz| 亚洲欧洲av一区二区| 伊人久久婷婷| 欧美日韩专区| 久久精品女人天堂| 亚洲麻豆一区| 久久久夜夜夜| 亚洲午夜小视频| 狠狠做深爱婷婷久久综合一区| 欧美—级在线免费片| 午夜精品亚洲一区二区三区嫩草| 欧美高清视频在线播放| 亚洲欧美综合| 亚洲精品专区| 好吊一区二区三区| 欧美三级日本三级少妇99| 久久网站热最新地址| 一区二区三区免费观看| 欧美成人综合在线| 欧美在线免费一级片| 一区二区三区高清| 在线精品视频一区二区| 国产欧美精品一区| 欧美日韩免费观看一区| 麻豆久久婷婷| 久久动漫亚洲| 亚洲综合欧美日韩| 夜夜嗨一区二区| 欧美激情片在线观看| 久久久国产成人精品| 亚洲欧美国产77777| 亚洲美女一区| 91久久国产综合久久| 国内外成人在线视频| 国产精品一二三四| 欧美日韩一区二区三区在线| 欧美高清视频在线观看| 开元免费观看欧美电视剧网站| 午夜宅男久久久| 亚洲女性裸体视频| 亚洲无限av看| 亚洲图片在线观看| 亚洲四色影视在线观看| 99国产精品久久久久久久| 亚洲国产日韩欧美一区二区三区| 久久综合久色欧美综合狠狠 | 欧美.www| 欧美肥婆在线| 欧美成人一区二区三区| 欧美成人午夜视频| 欧美黄色一级视频| 亚洲国产一区二区精品专区| 亚洲福利在线看| 亚洲激情电影中文字幕| 亚洲韩国青草视频| 亚洲国产网站| 亚洲最新视频在线| 亚洲性线免费观看视频成熟| 亚洲天堂黄色| 欧美亚洲在线观看| 久久永久免费| 欧美精品一区二区三| 欧美日韩免费在线观看| 国产精品久久久对白| 国产欧美一区二区三区国产幕精品 | 亚洲高清毛片| 99精品视频免费全部在线| 国产精品99久久久久久白浆小说| 亚洲在线一区二区| 久久久久99| 亚洲第一主播视频| 99精品国产热久久91蜜凸| 亚洲一线二线三线久久久| 欧美一区二区视频在线观看2020| 久久精品99国产精品酒店日本| 浪潮色综合久久天堂| 欧美久久影院| 国产日韩一区二区三区在线| 在线成人免费视频| 亚洲视频导航| 久久亚洲精品伦理| 亚洲精品小视频| 欧美一级在线亚洲天堂| 欧美成人精品在线视频| 国产精品福利网站| 亚洲二区在线视频| 亚洲嫩草精品久久| 美女黄毛**国产精品啪啪| 99成人在线| 久久精品视频在线免费观看| 欧美理论在线播放| 狠狠入ady亚洲精品| 中文高清一区| 欧美aⅴ99久久黑人专区| 一本久道久久综合婷婷鲸鱼| 久久精品视频免费| 国产精品国码视频| 亚洲国产欧美在线| 久久天天躁狠狠躁夜夜av| 日韩午夜在线观看视频| 久久视频在线看| 国产女人精品视频| 一区二区三区高清视频在线观看| 久久久中精品2020中文| 亚洲视频中文| 欧美精品aa| 亚洲第一福利在线观看| 久久精品国产清自在天天线| 亚洲精品色图| 欧美成人情趣视频| 亚洲电影专区| 久久午夜视频| 欧美一级成年大片在线观看| 国产精品久久久久久久久久久久久|