标签:个数 sub main mes href cpp while 并且 void
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll P = 131;
char str[2020];
bool good[200];
ull Hash[2020];
int sum[2020];
ull p[2020];
map<ull, ll>mp;
void solve() {
cin >> (str + 1);
string s;cin >> s;
for (int i = 0; i < s.size(); i ++) {
if (s[i] == ‘1‘) good[‘a‘ + i] = 1;
}
int k;cin >> k;
Hash[0] = 0;
p[0] = 1;
int n = strlen(str + 1);
for (int i = 1; i <= n; i ++) {
Hash[i] = Hash[i-1] * P + str[i];
p[i] = p[i-1] * P;
sum[i] = sum[i-1];
if (!good[str[i]])sum[i]++;
}
ll ans = 0;
for (int i = 1; i <=n; i ++) {
for (int j = i ; j <= n; j ++) {
ull x = Hash[j] -Hash[i-1] * p[(j - (i - 1))];
if (sum[j] - sum[i-1] <= k) {
if (!mp.count(x)) {
//cout << i << " " << j << endl;
mp[x] = 1;
ans++;
}
}
}
}
cout << ans << endl;
}
int main() {
int t = 1;//cin >> t;
while (t--)solve();
}
标签:个数 sub main mes href cpp while 并且 void
原文地址:https://www.cnblogs.com/Xiao-yan/p/14788721.html