C. String Equality:题目
我也不知道这算不算dp....虽然它有一个dp的标签
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> a((int)6e5);
vector<int> b((int)6e5), c((int)6e5);
const int mod = 1e9 + 7;
int mp1[30],mp2[30];
string str1, str2;
signed main()
{
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
cin >> str1;
cin >> str2;
sort(str1.begin(), str1.end());
sort(str2.begin(), str2.end());
for (int i = 0; i <= 26; i++)
mp1[i] = mp2[i] = 0;
for (int i = 0; i < n; i++)
{
mp1[str1[i] - 'a']++;
mp2[str2[i] - 'a']++;
}
int ff = 1;
int cou = 0;
for (int i = 0; i < 26; i++)
{
if (mp1[i] < mp2[i])
{
int u = mp2[i] - mp1[i];
if (u % k)
ff = 0;
else if (cou >= u / k)
cou -= u / k;
else
ff = 0;
}
else
{
int u = mp1[i] - mp2[i];
if (u % k)
ff = 0;
else
cou += u / k;
}
}
if (ff)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}