插入乘号

二进制枚举, 枚举乘号的位置

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
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int n, m;
string s;
cin >> n >> m >> s;
int cnt = n - 1;
LL ans = 0;
for (int i = 0; i < 1 << cnt; i ++)
{
int t = 0;
for (int j = 0; j < cnt; j ++)
{
t += i >> j & 1;
}

if (t == m)
{
LL res = 1;
string str = s.substr(0, 1);
for (int j = 0; j < cnt; j ++)
{
if (i >> j & 1)
{
res *= stoll(str);
str = s.substr(j + 1, 1);
}
else
{
str += s[j + 1];
}
}
res *= stoll(str);
ans = max(ans, res);
}
}

cout << ans << endl;
}

最近在学前端的东西,自己一个人搞全栈开发要学好多东西啊
收到了字节青训营的入营通知,希望接下来能认真学到点前端的东西,最好混到个证书