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

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 的代碼——本來只是想偷懶拷貝一下元素表的,一不小心看到了代碼,于是。。。

因為學習了代碼,感覺思路還是挺簡單的,動態(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);  // 超時
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 閱讀(1545) 評論(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>
            久久精品视频亚洲| 老色鬼久久亚洲一区二区| 欧美视频一区二区三区四区| 夜夜夜精品看看| 伊人久久大香线蕉av超碰演员| 久久久91精品| 久久综合狠狠| aa成人免费视频| 亚洲视频一二三| 国产日韩精品一区二区浪潮av| 久久久不卡网国产精品一区| 久久精品视频在线播放| 亚洲欧洲在线一区| av成人激情| 狠狠色伊人亚洲综合网站色| 欧美大片免费看| 欧美日韩中文字幕| 久久亚洲风情| 欧美日韩国产高清视频| 久久成人人人人精品欧| 裸体一区二区三区| 亚洲免费中文| 久久一区二区三区国产精品| 在线视频精品| 久久手机精品视频| 亚洲图片你懂的| 久久久噜噜噜久噜久久| 一区二区三区波多野结衣在线观看| 亚洲综合成人在线| 亚洲精品在线二区| 久久不见久久见免费视频1| 亚洲日本久久| 久久国产精品网站| 亚洲在线成人| 欧美大片免费看| 久久精品日产第一区二区| 欧美国产大片| 久久亚洲一区二区| 国产精品毛片在线| 亚洲精品少妇网址| 亚洲电影免费观看高清完整版在线 | 国产一区二区三区四区在线观看| 亚洲第一精品在线| 久久超碰97人人做人人爱| 一二美女精品欧洲| 欧美18av| 老司机一区二区三区| 国产欧美一区视频| 一区二区三区 在线观看视| 亚洲欧洲久久| 久久深夜福利免费观看| 久久国产精品99久久久久久老狼| 欧美日韩午夜在线| 亚洲巨乳在线| 99精品国产福利在线观看免费| 久久久噜噜噜久噜久久| 久久色在线观看| 国产欧美日韩精品a在线观看| 一区二区电影免费在线观看| 一区二区免费在线视频| 欧美成人伊人久久综合网| 蜜桃av一区二区| 亚洲国产99| 快播亚洲色图| 亚洲国产成人91精品| 亚洲国产精品va在线观看黑人 | 亚洲国产成人在线视频| 亚洲国产精品免费| 麻豆久久精品| 亚洲黄色成人| 一本久道综合久久精品| 欧美日韩亚洲91| 亚洲视频图片小说| 欧美伊人久久久久久久久影院| 国产精品一区在线观看| 性色av一区二区三区| 久久久噜噜噜久久中文字幕色伊伊| 国产日韩欧美不卡| 久久不射中文字幕| 欧美成人综合网站| 日韩午夜激情电影| 欧美性做爰猛烈叫床潮| 久久综合五月| 亚洲国产视频直播| 欧美日韩麻豆| 亚洲欧美日韩在线观看a三区| 久久精品国产久精国产一老狼| 国产亚洲欧美在线| 久久字幕精品一区| 亚洲精品国产精品乱码不99按摩| 亚洲图片激情小说| 国产日韩欧美自拍| 欧美成人精品| 亚洲一区二区三| 欧美成人高清视频| 亚洲一区观看| 一区二区三区在线免费观看| 欧美区二区三区| 亚洲欧美日韩国产综合在线 | 欧美高清在线观看| 亚洲午夜精品一区二区| 国产一区自拍视频| 欧美久久在线| 欧美亚洲视频一区二区| 亚洲国产日韩欧美在线99| 亚洲欧美在线看| 亚洲人成人一区二区在线观看 | 狼人天天伊人久久| 亚洲婷婷在线| 亚洲国产精品第一区二区| 午夜视频在线观看一区| 亚洲激情电影在线| 国产一区二区高清视频| 欧美日本一道本| 久久人人看视频| 亚洲资源av| 99精品福利视频| 亚洲大胆美女视频| 在线成人性视频| 国产伦精品一区二区三区照片91| 欧美 日韩 国产精品免费观看| 亚洲一品av免费观看| 亚洲国产精品日韩| 老司机67194精品线观看| 欧美一级片久久久久久久| 一区二区精品| 亚洲片在线资源| 狠狠色狠狠色综合人人| 国产欧美精品va在线观看| 欧美日韩影院| 欧美日韩免费一区| 欧美精品一区二区三区蜜臀| 久久亚洲精品伦理| 久久精品男女| 久久精品在线免费观看| 亚洲美女精品久久| 亚洲一区二区精品在线| 欧美日韩中文在线观看| 欧美高清视频| 欧美国产精品中文字幕| 久久综合久色欧美综合狠狠| 欧美专区亚洲专区| 亚洲一区www| 亚洲午夜一区| 亚洲欧美激情诱惑| 性欧美1819性猛交| 欧美亚洲在线观看| 久久爱www| 久久久久久久高潮| 美女尤物久久精品| 欧美激情一区二区三区在线视频观看 | 一本久道综合久久精品| a4yy欧美一区二区三区| 一区二区精品在线观看| 夜夜嗨av一区二区三区四区 | 亚洲欧洲日韩女同| 欧美激情导航| 亚洲激情另类| 一本色道久久99精品综合| 亚洲一区免费观看| 久久国产精品免费一区| 麻豆精品在线播放| 欧美日韩在线免费视频| 国产精品你懂得| 韩日在线一区| 亚洲精品久久久久久久久久久| 艳妇臀荡乳欲伦亚洲一区| 午夜精品国产| 巨乳诱惑日韩免费av| 亚洲国产精品女人久久久| 99一区二区| 久久aⅴ国产紧身牛仔裤| 快播亚洲色图| 国产精品国产自产拍高清av王其| 国产欧美日韩综合一区在线观看 | 狠狠色2019综合网| 日韩午夜在线观看视频| 午夜精品久久久久久久99水蜜桃 | 99精品视频免费观看视频| 午夜精品久久久久久久男人的天堂 | 欧美大香线蕉线伊人久久国产精品| 亚洲激情电影在线| 欧美亚洲系列| 欧美日本在线看| 激情成人亚洲| 亚洲欧美在线一区二区| 欧美成人一区二免费视频软件| 一区二区三区色| 久久免费视频在线| 国产精品伦子伦免费视频| 91久久国产精品91久久性色| 亚洲欧美日韩精品久久久| 欧美黑人在线播放| 欧美在线你懂的| 欧美日韩在线观看视频| 亚洲国产精品传媒在线观看 | 欧美r片在线| 亚洲欧美日韩中文播放| 欧美区亚洲区| 亚洲精品美女在线观看|