1039 - } string ret; for(int i=2;i<SIZ;i++){...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<iostream> #include<map> #include<set> using namespace std; enum { SIZ = 21, }; int num; int mark[SIZ]; map<string,string> table; map<string,string>::iterator iter; for(int i=2;i<SIZ;i++){ if(mark[i]== 0) continue; k += (char)i; } } int t,i; for(t=v;t<SIZ;t+=v){ if(mark[t] == 1){ mark[t] =0; tab.insert(t); } for(i=2;i+t<SIZ;i++){ if(mark[i] == 1) continue; if(mark[i+t] == 1){ tab.insert(i+t); mark[i+t] = 0; } } } } for(set<int>::iterator it=t.begin(); it!=t.end(); ++it){ mark[*it] = 1; } } string fun(){ string key; gen(key); if(key.length() <= 1){ return key; } else if( (iter=table.find(key) )!= table.end()){ return iter->second;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } string ret; for(int i=2;i&lt;SIZ;i++){ if(mark[i] == 0){ continue; } set&lt;int&gt; tab; remove(tab, i); string t = fun(); if(t[0] == 0){ ret += (char)i; } restore(tab); } return table[key] = ret; } int main(){ int tstnum = 0, tstcase; int t; string s; cin&gt;&gt;tstcase; while(tstnum &lt; tstcase){ memset(mark, 0, sizeof(mark)); cin&gt;&gt;num; for(int i=0;i&lt;num;i++){ cin&gt;&gt;t; mark[t] = true; } cout&lt;&lt;&quot;Scenario #&quot;&lt;&lt;++tstnum&lt;&lt;&quot;:\n&quot;; s = fun(); if( s[0] != 0 ){ cout&lt;&lt;&quot;The winning moves are:&quot;; for(t=0;t&lt;s.length();t++){ cout&lt;&lt;&quot; &quot;&lt;&lt;int(s[t]); } cout&lt;&lt;&quot;.\n&quot;; } else { cout&lt;&lt;&quot;There is no winning move.\n&quot;; } cout&lt;&lt;endl; } return 0; }...
View Full Document

Page1 / 2

1039 - } string ret; for(int i=2;i&amp;amp;lt;SIZ;i++){...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online