-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchNumbersEasy.cpp
More file actions
69 lines (59 loc) · 1.75 KB
/
MatchNumbersEasy.cpp
File metadata and controls
69 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << ": " << x << endl
string dp[51]; // n=[1,50] 1-based index, n=no. of matches
class MatchNumbersEasy {
public:
string maxNumber(vector<int> matches, int n) {
for(int i=0; i<51; ++i) dp[i]="";
int N = matches.size();
for(int i=0; i<N; ++i) {
dp[matches[i]] = (char)('0'+i);
}
for(int i=2; i<=n; ++i) {
for(int j=0; j<=i/2; ++j) {
string run = dp[j]+dp[i-j];
sort(run.begin(), run.end());
reverse(run.begin(), run.end());
if((run.size()>dp[i].size() && run[0]!='0') || (run.size()==dp[i].size() && run>dp[i]))
dp[i]=run;
}
}
string ret = dp[n];
if(count(ret.begin(), ret.end(), '0')==ret.size()) return "0";
return ret;
}
};
// CUT begin
//------------------------------------------------------------------------------
const double CASE_TIME_OUT = 2.0;
bool disabledTest(int x)
{
return x < 0;
}
template<class I, class O> vector<pair<I,O>> getTestCases() { return {
{ { {6,7,8}, 21 }, {"210"} },
{ { {5,23,24}, 30 }, {"20"} },
{ { {1,5,3,2}, 1 }, {"0"} },
{ { {1,1,1,1,1,1,1,1,1,1}, 50 }, {"99999999999999999999999999999999999999999999999999"} },
// Your custom test goes here:
//{ { {}, }, {} },
};}
//------------------------------------------------------------------------------
// Tester code:
//#define DISABLE_THREADS
#include "tester.cpp"
struct input {
vector<int> p0;int p1;
string run(MatchNumbersEasy* x) {
return x->maxNumber(p0,p1);
}
void print() { Tester::printArgs(p0,p1); }
};
int main() {
return Tester::runTests<MatchNumbersEasy>(
getTestCases<input, Tester::output<string>>(), disabledTest,
500, 1484476403, CASE_TIME_OUT, Tester::COMPACT_REPORT
);
}
// CUT end