Hex Artifact Content
Not logged in

Artifact 7881a6a8a8d93b4dca40428612b3abf7b04d6a3d:


0000: 23 69 6e 63 6c 75 64 65 20 3c 69 6f 73 74 72 65  #include <iostre
0010: 61 6d 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73  am>..#include <s
0020: 73 74 72 65 61 6d 3e 0d 0a 23 69 6e 63 6c 75 64  stream>..#includ
0030: 65 20 3c 69 6f 6d 61 6e 69 70 3e 0d 0a 23 69 6e  e <iomanip>..#in
0040: 63 6c 75 64 65 20 3c 76 65 63 74 6f 72 3e 0d 0a  clude <vector>..
0050: 23 69 6e 63 6c 75 64 65 20 3c 73 74 72 69 6e 67  #include <string
0060: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 6d 61 70  >..#include <map
0070: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 73 65 74  >..#include <set
0080: 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 61 6c 67  >..#include <alg
0090: 6f 72 69 74 68 6d 3e 0d 0a 23 69 6e 63 6c 75 64  orithm>..#includ
00a0: 65 20 3c 6e 75 6d 65 72 69 63 3e 0d 0a 23 69 6e  e <numeric>..#in
00b0: 63 6c 75 64 65 20 3c 69 74 65 72 61 74 6f 72 3e  clude <iterator>
00c0: 0d 0a 23 69 6e 63 6c 75 64 65 20 3c 63 6f 6d 70  ..#include <comp
00d0: 6c 65 78 3e 0d 0a 23 69 6e 63 6c 75 64 65 20 3c  lex>..#include <
00e0: 71 75 65 75 65 3e 0d 0a 23 69 6e 63 6c 75 64 65  queue>..#include
00f0: 20 3c 73 74 61 63 6b 3e 0d 0a 23 69 6e 63 6c 75   <stack>..#inclu
0100: 64 65 20 3c 63 6d 61 74 68 3e 0d 0a 75 73 69 6e  de <cmath>..usin
0110: 67 20 6e 61 6d 65 73 70 61 63 65 20 73 74 64 3b  g namespace std;
0120: 0d 0a 74 79 70 65 64 65 66 20 6c 6f 6e 67 20 6c  ..typedef long l
0130: 6f 6e 67 20 4c 4c 3b 0d 0a 0d 0a 73 74 61 74 69  ong LL;....stati
0140: 63 20 63 6f 6e 73 74 20 69 6e 74 20 4d 4f 44 4e  c const int MODN
0150: 55 4d 20 3d 20 31 30 30 30 30 30 30 30 30 37 3b  UM = 1000000007;
0160: 0d 0a 0d 0a 2f 2f 20 6d 61 6b 65 20 5b 69 2c 6a  ....// make [i,j
0170: 29 20 62 79 20 6b 5b 7a 2e 2e 24 5d 0d 0a 4c 4c  ) by k[z..$]..LL
0180: 20 64 70 5b 33 31 5d 5b 33 31 5d 5b 35 31 5d 5b   dp[31][31][51][
0190: 35 31 5d 3b 0d 0a 0d 0a 63 6c 61 73 73 20 52 65  51];....class Re
01a0: 76 65 72 73 65 52 65 73 6f 75 72 63 65 73 0d 0a  verseResources..
01b0: 7b 0d 0a 70 75 62 6c 69 63 3a 0d 0a 09 69 6e 74  {..public:...int
01c0: 20 66 69 6e 64 44 65 63 6f 6d 70 6f 73 69 74 69   findDecompositi
01d0: 6f 6e 73 28 73 74 72 69 6e 67 20 73 74 72 2c 20  ons(string str, 
01e0: 76 65 63 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20  vector <string> 
01f0: 72 65 73 6f 75 72 63 65 73 29 20 0d 0a 09 7b 0d  resources) ...{.
0200: 0a 09 09 6d 65 6d 73 65 74 28 64 70 2c 20 30 78  ...memset(dp, 0x
0210: 66 66 2c 20 73 69 7a 65 6f 66 28 64 70 29 29 3b  ff, sizeof(dp));
0220: 0d 0a 0d 0a 09 09 4c 4c 20 73 75 6d 20 3d 20 30  ......LL sum = 0
0230: 3b 0d 0a 09 09 66 6f 72 28 69 6e 74 20 6b 3d 30  ;....for(int k=0
0240: 3b 20 6b 3c 72 65 73 6f 75 72 63 65 73 2e 73 69  ; k<resources.si
0250: 7a 65 28 29 3b 20 2b 2b 6b 29 0d 0a 09 09 09 73  ze(); ++k).....s
0260: 75 6d 20 3d 20 28 73 75 6d 20 2b 20 72 65 63 28  um = (sum + rec(
0270: 30 2c 20 73 74 72 2e 73 69 7a 65 28 29 2c 20 6b  0, str.size(), k
0280: 2c 20 30 2c 20 73 74 72 2c 20 72 65 73 6f 75 72  , 0, str, resour
0290: 63 65 73 2c 20 64 70 29 29 20 25 20 4d 4f 44 4e  ces, dp)) % MODN
02a0: 55 4d 3b 0d 0a 09 09 72 65 74 75 72 6e 20 73 75  UM;....return su
02b0: 6d 3b 0d 0a 09 7d 0d 0a 0d 0a 09 4c 4c 20 72 65  m;...}.....LL re
02c0: 63 28 69 6e 74 20 69 2c 20 69 6e 74 20 6a 2c 20  c(int i, int j, 
02d0: 69 6e 74 20 6b 2c 20 69 6e 74 20 7a 2c 20 73 74  int k, int z, st
02e0: 72 69 6e 67 26 20 73 2c 20 76 65 63 74 6f 72 3c  ring& s, vector<
02f0: 73 74 72 69 6e 67 3e 26 20 72 73 2c 20 4c 4c 20  string>& rs, LL 
0300: 64 70 5b 33 31 5d 5b 33 31 5d 5b 35 31 5d 5b 35  dp[31][31][51][5
0310: 31 5d 20 29 0d 0a 09 7b 0d 0a 09 09 69 66 28 20  1] )...{....if( 
0320: 64 70 5b 69 5d 5b 6a 5d 5b 6b 5d 5b 7a 5d 20 3e  dp[i][j][k][z] >
0330: 3d 20 30 20 29 0d 0a 09 09 09 72 65 74 75 72 6e  = 0 ).....return
0340: 20 64 70 5b 69 5d 5b 6a 5d 5b 6b 5d 5b 7a 5d 3b   dp[i][j][k][z];
0350: 0d 0a 0d 0a 09 09 73 74 72 69 6e 67 26 20 72 20  ......string& r 
0360: 3d 20 72 73 5b 6b 5d 3b 0d 0a 09 09 69 66 28 20  = rs[k];....if( 
0370: 7a 3d 3d 72 2e 73 69 7a 65 28 29 20 29 0d 0a 09  z==r.size() )...
0380: 09 09 72 65 74 75 72 6e 20 64 70 5b 69 5d 5b 6a  ..return dp[i][j
0390: 5d 5b 6b 5d 5b 7a 5d 20 3d 20 28 69 3d 3d 6a 20  ][k][z] = (i==j 
03a0: 3f 20 31 20 3a 20 30 29 3b 0d 0a 0d 0a 09 09 69  ? 1 : 0);......i
03b0: 66 28 20 72 5b 7a 5d 20 3d 3d 20 27 25 27 20 29  f( r[z] == '%' )
03c0: 0d 0a 09 09 7b 0d 0a 09 09 09 4c 4c 20 73 75 6d  ....{.....LL sum
03d0: 20 3d 20 30 3b 0d 0a 09 09 09 69 66 28 20 7a 2b   = 0;.....if( z+
03e0: 32 20 3d 3d 20 72 2e 73 69 7a 65 28 29 20 29 0d  2 == r.size() ).
03f0: 0a 09 09 09 7b 0d 0a 09 09 09 09 66 6f 72 28 69  ....{......for(i
0400: 6e 74 20 6b 6b 3d 30 3b 20 6b 6b 3c 72 73 2e 73  nt kk=0; kk<rs.s
0410: 69 7a 65 28 29 3b 20 2b 2b 6b 6b 29 0d 0a 09 09  ize(); ++kk)....
0420: 09 09 09 73 75 6d 20 3d 20 28 73 75 6d 20 2b 20  ...sum = (sum + 
0430: 72 65 63 28 69 2c 20 6a 2c 20 6b 6b 2c 20 30 2c  rec(i, j, kk, 0,
0440: 20 73 2c 20 72 73 2c 20 64 70 29 29 20 25 20 4d   s, rs, dp)) % M
0450: 4f 44 4e 55 4d 3b 0d 0a 09 09 09 7d 0d 0a 09 09  ODNUM;.....}....
0460: 09 65 6c 73 65 0d 0a 09 09 09 7b 0d 0a 09 09 09  .else.....{.....
0470: 09 66 6f 72 28 69 6e 74 20 6a 6a 3d 69 2b 31 3b  .for(int jj=i+1;
0480: 20 6a 6a 3c 6a 3b 20 2b 2b 6a 6a 29 0d 0a 09 09   jj<j; ++jj)....
0490: 09 09 7b 0d 0a 09 09 09 09 09 4c 4c 20 72 69 67  ..{.......LL rig
04a0: 68 74 20 3d 20 72 65 63 28 6a 6a 2c 20 6a 2c 20  ht = rec(jj, j, 
04b0: 6b 2c 20 7a 2b 32 2c 20 73 2c 20 72 73 2c 20 64  k, z+2, s, rs, d
04c0: 70 29 3b 0d 0a 09 09 09 09 09 69 66 28 20 72 69  p);.......if( ri
04d0: 67 68 74 20 29 20 7b 0d 0a 09 09 09 09 09 09 4c  ght ) {........L
04e0: 4c 20 6c 65 66 74 20 3d 20 30 3b 0d 0a 09 09 09  L left = 0;.....
04f0: 09 09 09 66 6f 72 28 69 6e 74 20 6b 6b 3d 30 3b  ...for(int kk=0;
0500: 20 6b 6b 3c 72 73 2e 73 69 7a 65 28 29 3b 20 2b   kk<rs.size(); +
0510: 2b 6b 6b 29 0d 0a 09 09 09 09 09 09 09 6c 65 66  +kk).........lef
0520: 74 20 3d 20 28 6c 65 66 74 20 2b 20 72 65 63 28  t = (left + rec(
0530: 69 2c 20 6a 6a 2c 20 6b 6b 2c 20 30 2c 20 73 2c  i, jj, kk, 0, s,
0540: 20 72 73 2c 20 64 70 29 29 20 25 20 4d 4f 44 4e   rs, dp)) % MODN
0550: 55 4d 3b 0d 0a 09 09 09 09 09 09 73 75 6d 20 3d  UM;........sum =
0560: 20 28 73 75 6d 20 2b 20 6c 65 66 74 2a 72 69 67   (sum + left*rig
0570: 68 74 29 20 25 20 4d 4f 44 4e 55 4d 3b 0d 0a 09  ht) % MODNUM;...
0580: 09 09 09 09 7d 0d 0a 09 09 09 09 7d 0d 0a 09 09  ....}......}....
0590: 09 7d 0d 0a 09 09 09 72 65 74 75 72 6e 20 64 70  .}.....return dp
05a0: 5b 69 5d 5b 6a 5d 5b 6b 5d 5b 7a 5d 20 3d 20 73  [i][j][k][z] = s
05b0: 75 6d 3b 0d 0a 09 09 7d 0d 0a 09 09 65 6c 73 65  um;....}....else
05c0: 0d 0a 09 09 7b 0d 0a 09 09 09 69 66 28 20 72 5b  ....{.....if( r[
05d0: 7a 5d 3d 3d 73 5b 69 5d 20 26 26 20 69 2b 31 3c  z]==s[i] && i+1<
05e0: 3d 6a 20 29 0d 0a 09 09 09 09 72 65 74 75 72 6e  =j )......return
05f0: 20 64 70 5b 69 5d 5b 6a 5d 5b 6b 5d 5b 7a 5d 20   dp[i][j][k][z] 
0600: 3d 20 72 65 63 28 69 2b 31 2c 6a 2c 6b 2c 7a 2b  = rec(i+1,j,k,z+
0610: 31 2c 73 2c 72 73 2c 64 70 29 3b 0d 0a 09 09 09  1,s,rs,dp);.....
0620: 65 6c 73 65 0d 0a 09 09 09 09 72 65 74 75 72 6e  else......return
0630: 20 64 70 5b 69 5d 5b 6a 5d 5b 6b 5d 5b 7a 5d 20   dp[i][j][k][z] 
0640: 3d 20 30 3b 0d 0a 09 09 7d 0d 0a 09 7d 0d 0a 0d  = 0;....}...}...
0650: 0a 2f 2f 20 42 45 47 49 4e 20 43 55 54 20 48 45  .// BEGIN CUT HE
0660: 52 45 0d 0a 09 70 75 62 6c 69 63 3a 0d 0a 09 76  RE...public:...v
0670: 6f 69 64 20 72 75 6e 5f 74 65 73 74 28 69 6e 74  oid run_test(int
0680: 20 43 61 73 65 29 20 7b 20 69 66 20 28 28 43 61   Case) { if ((Ca
0690: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
06a0: 73 65 20 3d 3d 20 30 29 29 20 74 65 73 74 5f 63  se == 0)) test_c
06b0: 61 73 65 5f 30 28 29 3b 20 69 66 20 28 28 43 61  ase_0(); if ((Ca
06c0: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
06d0: 73 65 20 3d 3d 20 31 29 29 20 74 65 73 74 5f 63  se == 1)) test_c
06e0: 61 73 65 5f 31 28 29 3b 20 69 66 20 28 28 43 61  ase_1(); if ((Ca
06f0: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
0700: 73 65 20 3d 3d 20 32 29 29 20 74 65 73 74 5f 63  se == 2)) test_c
0710: 61 73 65 5f 32 28 29 3b 20 69 66 20 28 28 43 61  ase_2(); if ((Ca
0720: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
0730: 73 65 20 3d 3d 20 33 29 29 20 74 65 73 74 5f 63  se == 3)) test_c
0740: 61 73 65 5f 33 28 29 3b 20 69 66 20 28 28 43 61  ase_3(); if ((Ca
0750: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
0760: 73 65 20 3d 3d 20 34 29 29 20 74 65 73 74 5f 63  se == 4)) test_c
0770: 61 73 65 5f 34 28 29 3b 20 69 66 20 28 28 43 61  ase_4(); if ((Ca
0780: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
0790: 73 65 20 3d 3d 20 35 29 29 20 74 65 73 74 5f 63  se == 5)) test_c
07a0: 61 73 65 5f 35 28 29 3b 20 69 66 20 28 28 43 61  ase_5(); if ((Ca
07b0: 73 65 20 3d 3d 20 2d 31 29 20 7c 7c 20 28 43 61  se == -1) || (Ca
07c0: 73 65 20 3d 3d 20 36 29 29 20 74 65 73 74 5f 63  se == 6)) test_c
07d0: 61 73 65 5f 36 28 29 3b 20 7d 0d 0a 09 70 72 69  ase_6(); }...pri
07e0: 76 61 74 65 3a 0d 0a 09 74 65 6d 70 6c 61 74 65  vate:...template
07f0: 20 3c 74 79 70 65 6e 61 6d 65 20 54 3e 20 73 74   <typename T> st
0800: 72 69 6e 67 20 70 72 69 6e 74 5f 61 72 72 61 79  ring print_array
0810: 28 63 6f 6e 73 74 20 76 65 63 74 6f 72 3c 54 3e  (const vector<T>
0820: 20 26 56 29 20 7b 20 6f 73 74 72 69 6e 67 73 74   &V) { ostringst
0830: 72 65 61 6d 20 6f 73 3b 20 6f 73 20 3c 3c 20 22  ream os; os << "
0840: 7b 20 22 3b 20 66 6f 72 20 28 74 79 70 65 6e 61  { "; for (typena
0850: 6d 65 20 76 65 63 74 6f 72 3c 54 3e 3a 3a 63 6f  me vector<T>::co
0860: 6e 73 74 5f 69 74 65 72 61 74 6f 72 20 69 74 65  nst_iterator ite
0870: 72 20 3d 20 56 2e 62 65 67 69 6e 28 29 3b 20 69  r = V.begin(); i
0880: 74 65 72 20 21 3d 20 56 2e 65 6e 64 28 29 3b 20  ter != V.end(); 
0890: 2b 2b 69 74 65 72 29 20 6f 73 20 3c 3c 20 27 5c  ++iter) os << '\
08a0: 22 27 20 3c 3c 20 2a 69 74 65 72 20 3c 3c 20 22  "' << *iter << "
08b0: 5c 22 2c 22 3b 20 6f 73 20 3c 3c 20 22 20 7d 22  \","; os << " }"
08c0: 3b 20 72 65 74 75 72 6e 20 6f 73 2e 73 74 72 28  ; return os.str(
08d0: 29 3b 20 7d 0d 0a 09 76 6f 69 64 20 76 65 72 69  ); }...void veri
08e0: 66 79 5f 63 61 73 65 28 69 6e 74 20 43 61 73 65  fy_case(int Case
08f0: 2c 20 63 6f 6e 73 74 20 69 6e 74 20 26 45 78 70  , const int &Exp
0900: 65 63 74 65 64 2c 20 63 6f 6e 73 74 20 69 6e 74  ected, const int
0910: 20 26 52 65 63 65 69 76 65 64 29 20 7b 20 63 65   &Received) { ce
0920: 72 72 20 3c 3c 20 22 54 65 73 74 20 43 61 73 65  rr << "Test Case
0930: 20 23 22 20 3c 3c 20 43 61 73 65 20 3c 3c 20 22   #" << Case << "
0940: 2e 2e 2e 22 3b 20 69 66 20 28 45 78 70 65 63 74  ..."; if (Expect
0950: 65 64 20 3d 3d 20 52 65 63 65 69 76 65 64 29 20  ed == Received) 
0960: 63 65 72 72 20 3c 3c 20 22 50 41 53 53 45 44 22  cerr << "PASSED"
0970: 20 3c 3c 20 65 6e 64 6c 3b 20 65 6c 73 65 20 7b   << endl; else {
0980: 20 63 65 72 72 20 3c 3c 20 22 46 41 49 4c 45 44   cerr << "FAILED
0990: 22 20 3c 3c 20 65 6e 64 6c 3b 20 63 65 72 72 20  " << endl; cerr 
09a0: 3c 3c 20 22 5c 74 45 78 70 65 63 74 65 64 3a 20  << "\tExpected: 
09b0: 5c 22 22 20 3c 3c 20 45 78 70 65 63 74 65 64 20  \"" << Expected 
09c0: 3c 3c 20 27 5c 22 27 20 3c 3c 20 65 6e 64 6c 3b  << '\"' << endl;
09d0: 20 63 65 72 72 20 3c 3c 20 22 5c 74 52 65 63 65   cerr << "\tRece
09e0: 69 76 65 64 3a 20 5c 22 22 20 3c 3c 20 52 65 63  ived: \"" << Rec
09f0: 65 69 76 65 64 20 3c 3c 20 27 5c 22 27 20 3c 3c  eived << '\"' <<
0a00: 20 65 6e 64 6c 3b 20 7d 20 7d 0d 0a 09 76 6f 69   endl; } }...voi
0a10: 64 20 74 65 73 74 5f 63 61 73 65 5f 30 28 29 20  d test_case_0() 
0a20: 7b 20 73 74 72 69 6e 67 20 41 72 67 30 20 3d 20  { string Arg0 = 
0a30: 22 45 72 72 6f 72 20 69 6e 20 6d 6f 64 75 6c 65  "Error in module
0a40: 20 66 6f 6f 2c 20 63 6f 64 65 20 31 32 33 2e 22   foo, code 123."
0a50: 3b 20 73 74 72 69 6e 67 20 41 72 72 31 5b 5d 20  ; string Arr1[] 
0a60: 3d 20 7b 22 66 6f 6f 22 2c 20 22 31 32 33 22 2c  = {"foo", "123",
0a70: 20 22 45 72 72 6f 72 20 69 6e 20 6d 6f 64 75 6c   "Error in modul
0a80: 65 20 25 73 2e 22 2c 20 22 25 73 2c 20 63 6f 64  e %s.", "%s, cod
0a90: 65 20 25 73 22 7d 3b 20 76 65 63 74 6f 72 20 3c  e %s"}; vector <
0aa0: 73 74 72 69 6e 67 3e 20 41 72 67 31 28 41 72 72  string> Arg1(Arr
0ab0: 31 2c 20 41 72 72 31 20 2b 20 28 73 69 7a 65 6f  1, Arr1 + (sizeo
0ac0: 66 28 41 72 72 31 29 20 2f 20 73 69 7a 65 6f 66  f(Arr1) / sizeof
0ad0: 28 41 72 72 31 5b 30 5d 29 29 29 3b 20 69 6e 74  (Arr1[0]))); int
0ae0: 20 41 72 67 32 20 3d 20 31 3b 20 76 65 72 69 66   Arg2 = 1; verif
0af0: 79 5f 63 61 73 65 28 30 2c 20 41 72 67 32 2c 20  y_case(0, Arg2, 
0b00: 66 69 6e 64 44 65 63 6f 6d 70 6f 73 69 74 69 6f  findDecompositio
0b10: 6e 73 28 41 72 67 30 2c 20 41 72 67 31 29 29 3b  ns(Arg0, Arg1));
0b20: 20 7d 0d 0a 09 76 6f 69 64 20 74 65 73 74 5f 63   }...void test_c
0b30: 61 73 65 5f 31 28 29 20 7b 20 73 74 72 69 6e 67  ase_1() { string
0b40: 20 41 72 67 30 20 3d 20 22 54 68 65 20 66 6f 78   Arg0 = "The fox
0b50: 20 6a 75 6d 70 65 64 20 6f 76 65 72 20 74 68 65   jumped over the
0b60: 20 64 6f 67 2e 22 3b 20 73 74 72 69 6e 67 20 41   dog."; string A
0b70: 72 72 31 5b 5d 20 3d 20 7b 22 54 68 65 20 66 6f  rr1[] = {"The fo
0b80: 78 20 25 73 20 6f 76 65 72 20 74 68 65 20 64 6f  x %s over the do
0b90: 67 2e 22 2c 0d 0a 20 22 6c 61 7a 79 22 2c 0d 0a  g.",.. "lazy",..
0ba0: 20 22 62 72 6f 77 6e 22 2c 0d 0a 20 22 6a 75 6d   "brown",.. "jum
0bb0: 70 25 73 22 2c 0d 0a 20 22 73 22 2c 0d 0a 20 22  p%s",.. "s",.. "
0bc0: 65 64 22 2c 0d 0a 20 22 54 68 65 20 25 73 22 2c  ed",.. "The %s",
0bd0: 0d 0a 20 22 66 6f 78 20 25 73 22 2c 0d 0a 20 22  .. "fox %s",.. "
0be0: 25 73 20 6f 76 65 72 20 25 73 22 2c 0d 0a 20 22  %s over %s",.. "
0bf0: 74 68 65 20 64 6f 67 2e 22 7d 3b 20 76 65 63 74  the dog."}; vect
0c00: 6f 72 20 3c 73 74 72 69 6e 67 3e 20 41 72 67 31  or <string> Arg1
0c10: 28 41 72 72 31 2c 20 41 72 72 31 20 2b 20 28 73  (Arr1, Arr1 + (s
0c20: 69 7a 65 6f 66 28 41 72 72 31 29 20 2f 20 73 69  izeof(Arr1) / si
0c30: 7a 65 6f 66 28 41 72 72 31 5b 30 5d 29 29 29 3b  zeof(Arr1[0])));
0c40: 20 69 6e 74 20 41 72 67 32 20 3d 20 35 3b 20 76   int Arg2 = 5; v
0c50: 65 72 69 66 79 5f 63 61 73 65 28 31 2c 20 41 72  erify_case(1, Ar
0c60: 67 32 2c 20 66 69 6e 64 44 65 63 6f 6d 70 6f 73  g2, findDecompos
0c70: 69 74 69 6f 6e 73 28 41 72 67 30 2c 20 41 72 67  itions(Arg0, Arg
0c80: 31 29 29 3b 20 7d 0d 0a 09 76 6f 69 64 20 74 65  1)); }...void te
0c90: 73 74 5f 63 61 73 65 5f 32 28 29 20 7b 20 73 74  st_case_2() { st
0ca0: 72 69 6e 67 20 41 72 67 30 20 3d 20 22 61 62 63  ring Arg0 = "abc
0cb0: 64 65 22 3b 20 73 74 72 69 6e 67 20 41 72 72 31  de"; string Arr1
0cc0: 5b 5d 20 3d 20 7b 22 25 73 63 25 73 22 2c 20 22  [] = {"%sc%s", "
0cd0: 62 22 2c 20 22 64 65 22 2c 20 22 61 25 73 22 7d  b", "de", "a%s"}
0ce0: 3b 20 76 65 63 74 6f 72 20 3c 73 74 72 69 6e 67  ; vector <string
0cf0: 3e 20 41 72 67 31 28 41 72 72 31 2c 20 41 72 72  > Arg1(Arr1, Arr
0d00: 31 20 2b 20 28 73 69 7a 65 6f 66 28 41 72 72 31  1 + (sizeof(Arr1
0d10: 29 20 2f 20 73 69 7a 65 6f 66 28 41 72 72 31 5b  ) / sizeof(Arr1[
0d20: 30 5d 29 29 29 3b 20 69 6e 74 20 41 72 67 32 20  0]))); int Arg2 
0d30: 3d 20 32 3b 20 76 65 72 69 66 79 5f 63 61 73 65  = 2; verify_case
0d40: 28 32 2c 20 41 72 67 32 2c 20 66 69 6e 64 44 65  (2, Arg2, findDe
0d50: 63 6f 6d 70 6f 73 69 74 69 6f 6e 73 28 41 72 67  compositions(Arg
0d60: 30 2c 20 41 72 67 31 29 29 3b 20 7d 0d 0a 09 76  0, Arg1)); }...v
0d70: 6f 69 64 20 74 65 73 74 5f 63 61 73 65 5f 33 28  oid test_case_3(
0d80: 29 20 7b 20 73 74 72 69 6e 67 20 41 72 67 30 20  ) { string Arg0 
0d90: 3d 20 22 61 62 63 64 65 22 3b 20 73 74 72 69 6e  = "abcde"; strin
0da0: 67 20 41 72 72 31 5b 5d 20 3d 20 7b 22 25 73 65  g Arr1[] = {"%se
0db0: 22 2c 20 22 61 25 73 22 2c 20 22 25 73 62 25 73  ", "a%s", "%sb%s
0dc0: 22 2c 20 22 25 73 63 25 73 22 2c 20 22 25 73 64  ", "%sc%s", "%sd
0dd0: 25 73 22 7d 3b 20 76 65 63 74 6f 72 20 3c 73 74  %s"}; vector <st
0de0: 72 69 6e 67 3e 20 41 72 67 31 28 41 72 72 31 2c  ring> Arg1(Arr1,
0df0: 20 41 72 72 31 20 2b 20 28 73 69 7a 65 6f 66 28   Arr1 + (sizeof(
0e00: 41 72 72 31 29 20 2f 20 73 69 7a 65 6f 66 28 41  Arr1) / sizeof(A
0e10: 72 72 31 5b 30 5d 29 29 29 3b 20 69 6e 74 20 41  rr1[0]))); int A
0e20: 72 67 32 20 3d 20 30 3b 20 76 65 72 69 66 79 5f  rg2 = 0; verify_
0e30: 63 61 73 65 28 33 2c 20 41 72 67 32 2c 20 66 69  case(3, Arg2, fi
0e40: 6e 64 44 65 63 6f 6d 70 6f 73 69 74 69 6f 6e 73  ndDecompositions
0e50: 28 41 72 67 30 2c 20 41 72 67 31 29 29 3b 20 7d  (Arg0, Arg1)); }
0e60: 0d 0a 09 76 6f 69 64 20 74 65 73 74 5f 63 61 73  ...void test_cas
0e70: 65 5f 34 28 29 20 7b 20 73 74 72 69 6e 67 20 41  e_4() { string A
0e80: 72 67 30 20 3d 20 22 61 61 61 61 61 22 3b 20 73  rg0 = "aaaaa"; s
0e90: 74 72 69 6e 67 20 41 72 72 31 5b 5d 20 3d 20 7b  tring Arr1[] = {
0ea0: 22 61 22 2c 22 25 73 25 73 22 7d 3b 20 76 65 63  "a","%s%s"}; vec
0eb0: 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 41 72 67  tor <string> Arg
0ec0: 31 28 41 72 72 31 2c 20 41 72 72 31 20 2b 20 28  1(Arr1, Arr1 + (
0ed0: 73 69 7a 65 6f 66 28 41 72 72 31 29 20 2f 20 73  sizeof(Arr1) / s
0ee0: 69 7a 65 6f 66 28 41 72 72 31 5b 30 5d 29 29 29  izeof(Arr1[0])))
0ef0: 3b 20 69 6e 74 20 41 72 67 32 20 3d 20 31 34 3b  ; int Arg2 = 14;
0f00: 20 76 65 72 69 66 79 5f 63 61 73 65 28 34 2c 20   verify_case(4, 
0f10: 41 72 67 32 2c 20 66 69 6e 64 44 65 63 6f 6d 70  Arg2, findDecomp
0f20: 6f 73 69 74 69 6f 6e 73 28 41 72 67 30 2c 20 41  ositions(Arg0, A
0f30: 72 67 31 29 29 3b 20 7d 0d 0a 09 76 6f 69 64 20  rg1)); }...void 
0f40: 74 65 73 74 5f 63 61 73 65 5f 35 28 29 20 7b 20  test_case_5() { 
0f50: 73 74 72 69 6e 67 20 41 72 67 30 20 3d 20 22 61  string Arg0 = "a
0f60: 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61  aaaaaaaaaaaaaaaa
0f70: 61 61 61 61 61 61 61 61 61 61 61 61 61 22 3b 20  aaaaaaaaaaaaa"; 
0f80: 73 74 72 69 6e 67 20 41 72 72 31 5b 5d 20 3d 20  string Arr1[] = 
0f90: 7b 22 61 22 2c 22 61 61 22 2c 22 25 73 25 73 22  {"a","aa","%s%s"
0fa0: 2c 22 25 73 61 22 2c 22 61 25 73 22 2c 22 61 61  ,"%sa","a%s","aa
0fb0: 61 22 2c 22 61 61 25 73 22 2c 22 61 25 73 61 22  a","aa%s","a%sa"
0fc0: 2c 0d 0a 22 61 25 73 25 73 22 2c 22 25 73 61 61  ,.."a%s%s","%saa
0fd0: 22 2c 22 25 73 61 25 73 22 2c 22 25 73 25 73 61  ","%sa%s","%s%sa
0fe0: 22 2c 22 25 73 25 73 25 73 22 2c 22 61 61 61 61  ","%s%s%s","aaaa
0ff0: 22 2c 0d 0a 22 61 61 61 25 73 22 2c 22 61 61 25  ",.."aaa%s","aa%
1000: 73 61 22 2c 22 61 61 25 73 25 73 22 2c 22 61 25  sa","aa%s%s","a%
1010: 73 61 61 22 2c 22 61 25 73 61 25 73 22 2c 22 61  saa","a%sa%s","a
1020: 25 73 25 73 61 22 2c 0d 0a 22 61 25 73 25 73 25  %s%sa",.."a%s%s%
1030: 73 22 2c 22 25 73 61 61 61 22 2c 22 25 73 61 61  s","%saaa","%saa
1040: 25 73 22 2c 22 25 73 61 25 73 61 22 2c 22 25 73  %s","%sa%sa","%s
1050: 61 25 73 25 73 22 2c 0d 0a 22 25 73 25 73 61 61  a%s%s",.."%s%saa
1060: 22 2c 22 25 73 25 73 61 25 73 22 2c 22 25 73 25  ","%s%sa%s","%s%
1070: 73 25 73 61 22 2c 22 25 73 25 73 25 73 25 73 22  s%sa","%s%s%s%s"
1080: 2c 22 61 61 61 61 61 22 2c 0d 0a 22 61 61 61 61  ,"aaaaa",.."aaaa
1090: 25 73 22 2c 22 61 61 61 25 73 61 22 2c 22 61 61  %s","aaa%sa","aa
10a0: 61 25 73 25 73 22 2c 22 61 61 25 73 61 61 22 2c  a%s%s","aa%saa",
10b0: 22 61 61 25 73 61 25 73 22 2c 0d 0a 22 61 61 25  "aa%sa%s",.."aa%
10c0: 73 25 73 61 22 2c 22 61 61 25 73 25 73 25 73 22  s%sa","aa%s%s%s"
10d0: 2c 22 61 25 73 61 61 61 22 2c 22 61 25 73 61 61  ,"a%saaa","a%saa
10e0: 25 73 22 2c 22 61 25 73 61 25 73 61 22 2c 0d 0a  %s","a%sa%sa",..
10f0: 22 61 25 73 61 25 73 25 73 22 2c 22 61 25 73 25  "a%sa%s%s","a%s%
1100: 73 61 61 22 2c 22 61 25 73 25 73 61 25 73 22 2c  saa","a%s%sa%s",
1110: 22 61 25 73 25 73 25 73 61 22 2c 0d 0a 22 61 25  "a%s%s%sa",.."a%
1120: 73 25 73 25 73 25 73 22 2c 22 25 73 61 61 61 61  s%s%s%s","%saaaa
1130: 22 2c 22 25 73 61 61 61 25 73 22 2c 22 25 73 61  ","%saaa%s","%sa
1140: 61 25 73 61 22 2c 22 25 73 61 61 25 73 25 73 22  a%sa","%saa%s%s"
1150: 7d 3b 20 76 65 63 74 6f 72 20 3c 73 74 72 69 6e  }; vector <strin
1160: 67 3e 20 41 72 67 31 28 41 72 72 31 2c 20 41 72  g> Arg1(Arr1, Ar
1170: 72 31 20 2b 20 28 73 69 7a 65 6f 66 28 41 72 72  r1 + (sizeof(Arr
1180: 31 29 20 2f 20 73 69 7a 65 6f 66 28 41 72 72 31  1) / sizeof(Arr1
1190: 5b 30 5d 29 29 29 3b 20 69 6e 74 20 41 72 67 32  [0]))); int Arg2
11a0: 20 3d 20 38 37 39 37 30 34 37 39 39 3b 20 76 65   = 879704799; ve
11b0: 72 69 66 79 5f 63 61 73 65 28 35 2c 20 41 72 67  rify_case(5, Arg
11c0: 32 2c 20 66 69 6e 64 44 65 63 6f 6d 70 6f 73 69  2, findDecomposi
11d0: 74 69 6f 6e 73 28 41 72 67 30 2c 20 41 72 67 31  tions(Arg0, Arg1
11e0: 29 29 3b 20 7d 0d 0a 09 76 6f 69 64 20 74 65 73  )); }...void tes
11f0: 74 5f 63 61 73 65 5f 36 28 29 20 7b 20 73 74 72  t_case_6() { str
1200: 69 6e 67 20 41 72 67 30 20 3d 20 22 61 61 22 3b  ing Arg0 = "aa";
1210: 20 73 74 72 69 6e 67 20 41 72 72 31 5b 5d 20 3d   string Arr1[] =
1220: 20 7b 22 61 22 2c 20 22 61 22 2c 20 22 25 73 25   {"a", "a", "%s%
1230: 73 22 2c 20 22 25 73 25 73 22 7d 3b 20 76 65 63  s", "%s%s"}; vec
1240: 74 6f 72 20 3c 73 74 72 69 6e 67 3e 20 41 72 67  tor <string> Arg
1250: 31 28 41 72 72 31 2c 20 41 72 72 31 20 2b 20 28  1(Arr1, Arr1 + (
1260: 73 69 7a 65 6f 66 28 41 72 72 31 29 20 2f 20 73  sizeof(Arr1) / s
1270: 69 7a 65 6f 66 28 41 72 72 31 5b 30 5d 29 29 29  izeof(Arr1[0])))
1280: 3b 20 69 6e 74 20 41 72 67 32 20 3d 20 38 3b 20  ; int Arg2 = 8; 
1290: 76 65 72 69 66 79 5f 63 61 73 65 28 36 2c 20 41  verify_case(6, A
12a0: 72 67 32 2c 20 66 69 6e 64 44 65 63 6f 6d 70 6f  rg2, findDecompo
12b0: 73 69 74 69 6f 6e 73 28 41 72 67 30 2c 20 41 72  sitions(Arg0, Ar
12c0: 67 31 29 29 3b 20 7d 0d 0a 0d 0a 2f 2f 20 45 4e  g1)); }....// EN
12d0: 44 20 43 55 54 20 48 45 52 45 0d 0a 7d 3b 0d 0a  D CUT HERE..};..
12e0: 2f 2f 20 42 45 47 49 4e 20 43 55 54 20 48 45 52  // BEGIN CUT HER
12f0: 45 20 0d 0a 69 6e 74 20 6d 61 69 6e 28 29 20 7b  E ..int main() {
1300: 20 52 65 76 65 72 73 65 52 65 73 6f 75 72 63 65   ReverseResource
1310: 73 28 29 2e 72 75 6e 5f 74 65 73 74 28 2d 31 29  s().run_test(-1)
1320: 3b 20 7d 0d 0a 2f 2f 20 45 4e 44 20 43 55 54 20  ; }..// END CUT 
1330: 48 45 52 45 0d 0a                                HERE..