SRM388div1 medium

使うギターを全探索するだけ。

#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

class GuitarConcert 
{
	public:

		vector<string> comp(vector<string> vs1,vector<string> vs2)
		{
			if(vs1.size()==vs2.size())
				return (vs1<vs2)?vs1:vs2;
			else
				return (vs1.size()<vs2.size())?vs1:vs2;
		}

		vector <string> buyGuitars(vector <string> guitarNames, vector <string> guitarSongs) 
		{
			int nG=guitarNames.size(),nS=guitarSongs[0].size(),maxPlay=0;

			vector<string> ans;
			for(int use=0;use<(1<<nG);use++)
			{
				set<int> se;
				vector<string> vs;
				for(int i=0;i<nG;i++)
					if(use & (1<<i))
					{
						vs.push_back(guitarNames[i]);
						for(int j=0;j<nS;j++)
							if(guitarSongs[i][j]=='Y')
								se.insert(j);
					}
				sort(vs.begin(),vs.end());

				if(maxPlay<se.size())
				{
					maxPlay=se.size();
					ans=vs;
				}
				else if(maxPlay==se.size())
					ans=comp(ans,vs);
				else
					;
			}
			return ans;
		}
};