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

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 閱讀(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>
            久久久xxx| 欧美怡红院视频一区二区三区| 嫩草国产精品入口| 亚洲国产成人精品久久久国产成人一区 | 亚洲精品国偷自产在线99热| 久久亚洲一区| 亚洲人成网站在线播| 亚洲国产精品va在线看黑人 | 亚洲影院一区| 国产一区二区av| 欧美成人精品在线| 欧美久久99| 欧美在线一区二区三区| 欧美在线播放一区二区| …久久精品99久久香蕉国产| 亚洲欧洲日本国产| 欧美性事免费在线观看| 久久国产精品久久久久久电车| 久久久久久久波多野高潮日日 | 国产亚洲va综合人人澡精品| 狼狼综合久久久久综合网| 久久久亚洲人| 亚洲综合色视频| 久久精品国产一区二区三区| 99国内精品久久| 午夜精品免费| 99亚洲精品| 久久精品动漫| 一区二区三区四区精品| 久久精品免费电影| 亚洲视频在线观看网站| 久久久999精品视频| 中文精品视频一区二区在线观看| 久久精品亚洲热| 亚洲午夜未删减在线观看| 久久久久九九九| 午夜精品一区二区在线观看| 免费人成精品欧美精品| 欧美在线免费视频| 欧美激情精品久久久久久黑人| 欧美资源在线观看| 欧美日韩成人一区| 欧美a级一区二区| 国产精品毛片| 亚洲六月丁香色婷婷综合久久| 国内精品伊人久久久久av影院 | 久久先锋影音| 国产精品免费网站| 亚洲激情在线| 亚洲激情视频在线| 欧美一级成年大片在线观看| 一区二区三区 在线观看视频| 久久综合给合久久狠狠狠97色69| 午夜精品久久久久久99热软件| 欧美人在线视频| 欧美激情亚洲| 伊人久久大香线蕉综合热线| 欧美在线视频免费| 午夜视频在线观看一区二区| 欧美午夜精品久久久| 亚洲第一伊人| 亚洲日本一区二区三区| 久久久亚洲一区| 久久综合福利| 在线看成人片| 久久久午夜电影| 欧美.日韩.国产.一区.二区| 在线播放不卡| 久久成人亚洲| 老司机免费视频一区二区| 狠狠色综合网| 免费观看久久久4p| 亚洲国产精品一区二区尤物区| 91久久极品少妇xxxxⅹ软件| 媚黑女一区二区| 亚洲国产毛片完整版| 日韩视频欧美视频| 欧美人成网站| 亚洲一二三四区| 久久久久9999亚洲精品| 极品尤物久久久av免费看| 久久视频国产精品免费视频在线| 欧美激情欧美激情在线五月| 99re6热只有精品免费观看| 欧美日本免费| 亚洲一区欧美一区| 久久久国产精品亚洲一区 | 国产精品你懂得| 欧美一区二区三区播放老司机| 久久综合久久综合久久| 亚洲国产小视频在线观看| 欧美日韩不卡| 香蕉成人啪国产精品视频综合网| 美女福利精品视频| 99精品国产福利在线观看免费| 国产精品久久一区主播| 欧美在线观看视频一区二区三区| 亚洲第一精品福利| 亚洲欧美日韩精品在线| 一区国产精品| 国产精品99免视看9| 久久精品论坛| av成人免费在线| 美国十次了思思久久精品导航| 日韩一二三在线视频播| 国产视频一区免费看| 你懂的网址国产 欧美| 亚洲一区在线播放| 亚洲国产精品成人| 久久精品99国产精品酒店日本| 亚洲精品日韩激情在线电影| 国产欧美一级| 欧美三级电影大全| 久久视频在线视频| 亚洲欧美文学| 一本色道久久综合狠狠躁篇的优点| 久久久久www| 亚洲欧美日本在线| 亚洲乱码国产乱码精品精天堂 | 99国产一区| 亚洲高清成人| 国产欧美日韩亚洲精品| 欧美日韩一区二| 欧美高清在线观看| 久久久久久日产精品| 亚洲综合色在线| 中文日韩电影网站| 亚洲精品123区| 亚洲承认在线| 蜜乳av另类精品一区二区| 欧美在线日韩精品| 亚洲女同精品视频| 亚洲天天影视| 亚洲一区不卡| 亚洲在线第一页| 亚洲视频在线观看三级| 一区二区三区日韩精品| 亚洲欧洲精品一区二区| 亚洲国产日本| 亚洲精品国偷自产在线99热| 亚洲成人在线视频网站| 韩国亚洲精品| 伊人久久婷婷| 亚洲国产另类久久精品| 亚洲成色777777女色窝| 伊人成人在线| 亚洲激情自拍| 亚洲另类在线视频| 一本色道久久综合亚洲精品高清| 99国产精品私拍| 亚洲午夜91| 午夜久久美女| 久久久久久穴| 欧美激情一区二区| 亚洲人成网在线播放| 夜夜狂射影院欧美极品| 一级成人国产| 欧美一区二区三区电影在线观看| 欧美在线网址| 欧美成人在线免费视频| 欧美精品日韩一区| 国产精品久久久久久亚洲毛片| 国产免费成人| 国模 一区 二区 三区| 在线成人小视频| 一区二区日韩伦理片| 亚洲欧美国产va在线影院| 久久精品免费电影| 欧美激情视频一区二区三区在线播放 | 亚洲欧洲av一区二区| 欧美专区日韩专区| 免费一级欧美片在线播放| 欧美理论视频| 国产免费成人av| 91久久久久久久久久久久久| 亚洲少妇最新在线视频| 久久精品人人做人人综合| 欧美丰满高潮xxxx喷水动漫| 99re6这里只有精品| 性色av一区二区怡红| 欧美国产精品专区| 国产欧美一区二区白浆黑人| 亚洲精品欧美激情| 午夜在线观看免费一区| 欧美激情一区二区久久久| 亚洲影院色在线观看免费| 免费亚洲婷婷| 国产视频观看一区| 日韩午夜免费视频| 久久激情视频| 亚洲精品乱码久久久久久按摩观| 亚洲欧美成人一区二区在线电影| 欧美成人一区二区三区| 国产欧美一区二区精品婷婷| av成人免费观看| 免费观看日韩| 欧美一区二区播放| 欧美视频成人| 日韩一级网站| 亚洲国产成人久久综合|