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

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>
            久久aⅴ国产紧身牛仔裤| 宅男精品视频| 久久综合一区二区三区| 在线国产精品一区| 欧美国产激情| 欧美视频在线观看视频极品| 午夜精品久久久久影视| 欧美一区二区三区在线播放| 国产亚洲欧美色| 欧美电影电视剧在线观看| 欧美精品啪啪| 久久se精品一区精品二区| 久久午夜影视| 亚洲视频视频在线| 欧美一区二区三区日韩视频| 亚洲国产一区在线| 亚洲午夜三级在线| 在线看国产日韩| 在线视频日本亚洲性| 国内一区二区三区在线视频| 亚洲激情自拍| 国产精品视频免费观看www| 老司机精品久久| 欧美午夜三级| 欧美激情一区二区三区在线| 国产精品揄拍500视频| 欧美高清视频一区| 国产酒店精品激情| 香蕉国产精品偷在线观看不卡| 欧美大片第1页| 欧美a级一区二区| 亚洲主播在线播放| 免费91麻豆精品国产自产在线观看| 亚洲视频免费| 久久久精品国产免费观看同学 | 最新中文字幕亚洲| 国产精品夜夜夜| 91久久精品美女| 黄色精品在线看| 亚洲一区二区三区色| 亚洲精品免费看| 久久久福利视频| 久久精品在线| 国产精品久久久久aaaa九色| 欧美激情精品久久久久久蜜臀| 国产欧美日韩精品丝袜高跟鞋| 亚洲免费av电影| 亚洲精选久久| 欧美3dxxxxhd| 欧美激情bt| 亚洲第一福利社区| 久久久午夜视频| 久久久久久婷| 国产视频一区二区在线观看 | 欧美一级理论性理论a| 亚洲综合第一| 国产精品国内视频| 一本久久精品一区二区| 99国产精品99久久久久久| 欧美大胆a视频| 亚洲福利视频网站| 91久久中文| 欧美激情亚洲视频| 亚洲精品美女| 亚洲视频精品在线| 欧美视频导航| 午夜精品一区二区三区在线视| 欧美一区二区三区成人| 国产色综合久久| 欧美一区二区三区四区夜夜大片| 久久九九国产精品| 亚洲国产成人av| 欧美国产精品人人做人人爱| 亚洲精选国产| 亚洲欧美另类综合偷拍| 国产欧美一级| 麻豆精品在线播放| 亚洲精品一区二区三区四区高清| 一区二区三区不卡视频在线观看| 欧美日韩亚洲一区二区| 亚洲欧美日韩视频二区| 久久婷婷激情| 日韩系列在线| 国产精品视频免费观看| 久久久久免费观看| 亚洲美女91| 久久久久国产精品麻豆ai换脸| 在线观看日韩av先锋影音电影院| 欧美 日韩 国产在线| 亚洲最新在线| 久久综合国产精品| 这里只有精品电影| 韩国女主播一区二区三区| 欧美国产欧美亚洲国产日韩mv天天看完整| 亚洲黑丝一区二区| 久久精品国产第一区二区三区最新章节| 韩国一区二区三区美女美女秀| 欧美成人综合在线| 午夜在线视频一区二区区别| 蜜臀久久久99精品久久久久久| 中文日韩在线| 亚洲风情在线资源站| 国产精品久久一区二区三区| 老司机成人网| 午夜精品电影| 99天天综合性| 亚洲第一在线综合在线| 欧美中文字幕| 一区二区三区色| 极品尤物一区二区三区| 国产精品美女诱惑| 女生裸体视频一区二区三区| 欧美一级淫片aaaaaaa视频| 亚洲精品国产精品国自产观看浪潮| 久久精品官网| 亚洲欧美日韩专区| 亚洲毛片在线免费观看| 激情久久久久久久久久久久久久久久| 欧美日韩亚洲综合| 欧美喷潮久久久xxxxx| 久久婷婷国产综合国色天香| 亚洲综合精品一区二区| 999亚洲国产精| 最新亚洲激情| 亚洲福利电影| 欧美大片免费久久精品三p| 久久精品国产999大香线蕉| 亚洲欧美日韩国产| 亚洲一区二区三区四区五区午夜| 亚洲人成小说网站色在线| 激情成人av| 好男人免费精品视频| 国产一区二区成人久久免费影院| 国产精品免费观看在线| 国产精品国产三级国产专区53| 欧美精品在线观看91| 欧美激情第六页| 欧美国产日本高清在线| 欧美电影免费网站| 欧美精品成人在线| 欧美精品一区二区三区一线天视频| 麻豆亚洲精品| 欧美寡妇偷汉性猛交| 欧美激情精品久久久久久久变态| 欧美国产1区2区| 欧美伦理91| 欧美色另类天堂2015| 国产精品免费电影| 国产亚洲一区在线播放| 伊人久久亚洲热| 亚洲国产欧洲综合997久久| 日韩亚洲不卡在线| 亚洲一区二区精品在线| 新片速递亚洲合集欧美合集| 久久疯狂做爰流白浆xx| 久久亚洲二区| 亚洲激情影院| 亚洲天堂成人在线观看| 新片速递亚洲合集欧美合集| 久久野战av| 欧美精品在线免费| 国产精品亚洲成人| 在线观看视频欧美| 一二三区精品福利视频| 欧美一区二区三区久久精品| 嫩草伊人久久精品少妇av杨幂| 亚洲欧洲日产国产综合网| 在线中文字幕不卡| 久久久精品国产免费观看同学| 欧美高清视频一二三区| 国产精品嫩草久久久久| 精品成人在线| 亚洲一区二区在线免费观看视频| 久久精品一本| 亚洲人午夜精品免费| 午夜日本精品| 欧美精品国产一区| 国产日韩欧美一区| 99香蕉国产精品偷在线观看| 欧美在线视频在线播放完整版免费观看| 米奇777在线欧美播放| 一本色道久久综合狠狠躁的推荐| 久久久久国产精品午夜一区| 欧美三日本三级少妇三2023 | 欧美成人精品福利| 国产欧美精品在线| 制服丝袜激情欧洲亚洲| 久久尤物视频| 午夜精品影院在线观看| 欧美美女操人视频| 亚洲春色另类小说| 欧美一区二区三区四区高清| 亚洲精选一区二区| 蜜臀va亚洲va欧美va天堂| 国产欧美日韩激情| 亚洲一区二区三区精品动漫| 亚洲电影在线播放| 久久久久久久久久久一区| 国产日韩精品入口| 午夜国产精品视频免费体验区|