1 条题解
-
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; string a, b; ll ans = 0; int n, m; void dfs(int p, int c, string u, int l, bool f) { if (c == l) { if (f) { if (u < b) ans++; } else { ans++; } return; } if (p == n) return; dfs(p + 1, c, u, l, f); if (c == 0 && a[p] == '0' && l > 1) return; if (f) { char ch = a[p]; if (u.empty()) { if (ch > b[0]) return; else if (ch == b[0]) { dfs(p + 1, c + 1, u + ch, l, true); } else { dfs(p + 1, c + 1, u + ch, l, false); } } else { if (ch > b[c]) return; bool nf = f && (ch == b[c]); dfs(p + 1, c + 1, u + ch, l, nf); } } else { dfs(p + 1, c + 1, u + a[p], l, false); } } int main() { cin >> a >> b; n = a.size(); m = b.size(); for (int l = 1; l < m; l++) { dfs(0, 0, "", l, false); } dfs(0, 0, "", m, true); cout << ans << endl; return 0; }
- 1
信息
- ID
- 998
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 7
- 标签
- 递交数
- 71
- 已通过
- 16
- 上传者