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

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.




學(xué)習(xí)了 fura2 的代碼——本來(lái)只是想偷懶拷貝一下元素表的,一不小心看到了代碼,于是。。。

因?yàn)閷W(xué)習(xí)了代碼,感覺(jué)思路還是挺簡(jiǎn)單的,動(dòng)態(tài)規(guī)劃。。

 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);  // 超時(shí)
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) 評(píng)論(1)  編輯 收藏 引用 所屬分類(lèi): ACM

Feedback

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

來(lái)踩一下~~  回復(fù)  更多評(píng)論   


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            91久久中文| 国产欧美一区二区三区沐欲| 国产日韩精品视频一区二区三区| 一本大道久久a久久综合婷婷| 你懂的亚洲视频| 另类尿喷潮videofree| 中日韩美女免费视频网址在线观看| 久久夜色精品| 91久久线看在观草草青青| 欧美激情中文字幕乱码免费| 久久综合99re88久久爱| 亚洲欧洲一区二区三区久久| 欧美激情一区二区| 欧美成人午夜激情视频| 日韩天堂在线观看| 欧美激情导航| 久久夜色精品国产| 91久久在线观看| 在线综合亚洲欧美在线视频| 欧美系列电影免费观看| 久久精品国产69国产精品亚洲| 久久久久91| 亚洲精品免费在线观看| 日韩视频一区二区| 国产日产欧美一区| 免费短视频成人日韩| 欧美日本网站| 久久精品亚洲精品| 欧美国产在线电影| 亚洲欧美视频一区| 久久精品国产一区二区三| 亚洲老司机av| 亚洲影院色无极综合| 伊人精品视频| 日韩午夜免费| 国产一在线精品一区在线观看| 亚洲国产精品成人va在线观看| 欧美精选在线| 午夜视频在线观看一区二区三区| 久久久精品性| 亚洲性视频网站| 欧美影院在线| 99视频精品全部免费在线| 亚洲在线观看| 亚洲另类黄色| 久久国内精品视频| 亚洲在线一区二区三区| 欧美大胆成人| 欧美福利视频一区| 国产精品羞羞答答xxdd| 亚洲黄色在线| 亚洲大片免费看| 亚洲一区二区三区免费视频| 亚洲激情欧美| 午夜欧美不卡精品aaaaa| 在线综合亚洲| 美女日韩在线中文字幕| 久久精品在线视频| 国产精品成人观看视频国产奇米| 亚洲成人在线视频播放 | 母乳一区在线观看| 久久精品久久综合| 国产精品啊啊啊| 亚洲精品视频免费观看| 日韩视频第一页| 欧美一级艳片视频免费观看| 在线一区免费观看| 欧美精品一二三| 亚洲国产美国国产综合一区二区| 国产一区白浆| 欧美一区二区三区日韩| 午夜精品久久久久久久| 欧美三级视频在线观看| 欧美成人一区二区三区片免费| 国产亚洲欧美另类一区二区三区| 一区二区激情视频| 亚洲九九精品| 欧美电影专区| 亚洲伦理中文字幕| 亚洲视频一区在线| 欧美日韩国产a| 亚洲精品黄色| 亚洲视频精选| 国产精品试看| 亚洲一区二区三区四区中文| 欧美一区在线直播| 国内久久精品视频| 久久在线播放| 亚洲国产精品精华液2区45| 亚洲国产美女| 欧美日韩国产成人| 亚洲午夜精品福利| 久久视频一区| 亚洲国产精品一区二区尤物区| 久久久久久久久岛国免费| 久久久久久久精| 在线观看91精品国产入口| 久久最新视频| 亚洲免费电影在线| 午夜久久久久久| 激情五月综合色婷婷一区二区| 久久免费精品视频| 亚洲人精品午夜| 亚洲欧美国产精品专区久久| 国产亚洲激情| 欧美激情精品久久久久久大尺度| 亚洲午夜未删减在线观看| 久久亚洲色图| 亚洲一区欧美激情| 亚洲大片免费看| 欧美系列精品| 男人的天堂亚洲| 一区二区激情视频| 欧美成人在线免费观看| 亚洲欧美高清| 亚洲日本欧美日韩高观看| 国产精品老牛| 欧美+日本+国产+在线a∨观看| 一本久久知道综合久久| 久久一区二区三区av| 亚洲精品一区中文| 国产日韩精品视频一区| 欧美精品一区二区精品网 | 欧美黄污视频| 性色av一区二区三区| 亚洲国产精品一区二区www在线| 欧美午夜不卡| 欧美大香线蕉线伊人久久国产精品| 亚洲免费婷婷| 在线一区免费观看| 亚洲精品日产精品乱码不卡| 麻豆免费精品视频| 久久精品免费| 午夜精品一区二区三区四区| 99re视频这里只有精品| 在线观看福利一区| 国产精品毛片一区二区三区| 欧美成人午夜激情在线| 久久综合九色综合欧美就去吻| 午夜精品福利一区二区三区av| 一区二区三区回区在观看免费视频| 老司机凹凸av亚洲导航| 久久久www成人免费无遮挡大片| 欧美一级黄色网| 午夜在线不卡| 欧美一区二区三区免费大片| 99v久久综合狠狠综合久久| 91久久国产自产拍夜夜嗨| 精品999久久久| 国产亚洲欧美一区二区三区| 国产精品激情| 国产精品乱人伦一区二区| 欧美视频在线观看免费网址| 欧美大片免费观看| 免费不卡在线观看| 久久午夜国产精品| 久久精品国产精品亚洲精品| 亚洲欧美日韩天堂| 久久gogo国模啪啪人体图| 性久久久久久久久久久久| 亚洲欧美经典视频| 性久久久久久久久| 欧美在线免费一级片| 西瓜成人精品人成网站| 欧美在线一二三区| 久久一区国产| 免费一区视频| 欧美日韩一级黄| 国产精品夜夜夜一区二区三区尤| 国产啪精品视频| 在线成人免费观看| 亚洲激情视频在线播放| 一区二区三区日韩欧美精品| 午夜日韩在线观看| 免费在线亚洲欧美| 一区二区免费在线播放| 欧美在线啊v| 欧美激情第二页| 国产精品久久久久9999吃药| 好吊妞**欧美| 亚洲精品欧洲| 欧美一区二区三区免费在线看| 老色鬼精品视频在线观看播放| 欧美大片免费久久精品三p| 欧美大色视频| 一区二区三区 在线观看视频| 欧美在线播放视频| 欧美日韩久久| 一区二区三区在线免费观看| a91a精品视频在线观看| 久久久999精品免费| 亚洲经典自拍| 久久精品国产亚洲aⅴ| 欧美gay视频| 国产一区二区在线免费观看| 日韩一本二本av| 美女国产一区| 亚洲四色影视在线观看| 久久这里只有精品视频首页| 国产精品国产三级国产专区53 |