SRM512 Div1 Easy(256), Div2 Medium(512) MysteriousRestaurant
何日レストランに行くかを決めれば、それぞれの曜日にどの料理を食べるのが最安かが決まる。
#include <string> #include <vector> #include <algorithm> using namespace std; int c2p( char c ) { if ( '0'<=c && c<='9' ) return c-'0'+0; if ( 'A'<=c && c<='Z' ) return c-'A'+10; if ( 'a'<=c && c<='z' ) return c-'a'+36; return -1; } class MysteriousRestaurant{public: int maxDays( vector <string> prices, int budget ) { int N = (int)prices.size(); int M = (int)prices[0].size(); for ( int i=N; i>0; i-- ) { vector<vector<int> > p( 7, vector<int>(M) ); for ( int j=0; j<i; j++ ) for ( int k=0; k<M; k++ ) p[j%7][k] += c2p(prices[j][k]); int b = 0; for ( int j=0; j<7; j++ ) b += *min_element(p[j].begin(),p[j].end()); if ( b<=budget ) return i; } return 0; }};