Cody

Solution 174326

Submitted on 7 Dec 2012 by J.R.! Menzinger
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
%% tic urlwrite('http://contest.usc.edu/index.php/Fall12/Home?action=download&upname=analysis.in.txt','analysis_in.txt') toc
ans = /users/msssystem3/analysis_in.txt Elapsed time is 0.319894 seconds.
2   Pass
%% fid=fopen('analysis_in.txt','r'); min_elements_expected=[2 0 1 2 0 3 4]; qty=fscanf(fid,'%i',1); for q=1:qty n = fscanf(fid,'%i %i\n',2)'; % cols / rows A=zeros(n)'; % Format is colmns, rows for i=1:n(2) strv = fgetl(fid); A(i,:) = strv - '0'; end strv=fgetl(fid); Sample=strv - '0'; min_elements=Chem_analysis(A,Sample); assert(isequal(min_elements,min_elements_expected(q))); end % for q fclose(fid); % The C Winning Solution % #include <iostream> % #include <fstream> % #include <string> % using namespace std; % int testcases; % int n, m; % int now; % int best; % string goal; % string s[1000]; % void search(int i, string status) % { % if (i == n) % { % if (status == goal) % { % if ((best < 0) || (now < best)) best = now; % } % return; % } % search(i + 1, status); % string tmp = status; % for (int j = 0; j < m; j ++) % { % if (s[i][j] == '1') tmp[j] = '1'; % } % now ++; % search(i + 1, tmp); % now --; % } % int main() % { % ifstream inf("analysis.in"); % inf >> testcases; % for (int testcase = 1; testcase <= testcases; testcase ++) % { % cout << "Data Set " << testcase << ":" << endl; % inf >> m >> n; % for (int i = 0; i < n; i ++) % inf >> s[i]; % inf >> goal; % best = -1; % string ini = ""; % for (int i = 0; i < m; i ++) % ini = ini + "0"; % now = 0; % search(0, ini); % if (best < 0) cout << "Impossible" << endl; else cout << best << endl; % cout << endl; % } % inf.close(); % return 0; % } % % %