#include"iostream"
#include"vector"
// #include"queue"
// #include"deque"
// #include"set"
#include"map"
#include"algorithm"
#include"cstring"
#define int long long
using namespace std;
const int modn = 1e9+7;
const int maxn = 2055;
int add(int a,int b){
return ((a+b)%modn+modn)%modn;
}
int mult(int a,int b){
return (a*b)%modn;
}
int c[maxn][maxn];
int dp[maxn][maxn];
int arr[maxn];
map<string,int> mp;
void solve(){
int n,k;
cin >> n >> k;
string str[n+5];
int num=1;
for(int i=0;i<n;i++){
cin >> str[i];
sort(str[i].begin(),str[i].end());
if(mp[str[i]]==0){
mp[str[i]]=num;
arr[num]=1;
num++;
}
else{
arr[mp[str[i]]]++;
}
}
c[0][0]=1;
for(int i=1;i<=n;i++){
c[i][0]=1;
for(int j=1;j<=i;j++){
c[i][j] = add(c[i][j],add(c[i-1][j-1],c[i-1][j]));
}
}
int disct = mp.size();
int ans=0;
dp[0][0]=1;
for(int i=1;i<=disct;i++){
for(int j=0;j<=k;j++){
for(int g=0;g<=arr[i] && j>=c[g][2];g++){
dp[i][j] = add(dp[i][j],mult(c[arr[i]][g] , dp[i-1][j-c[g][2]]));
}
}
}
cout << dp[disct][k];
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0);
// freopen("","r",stdin);freopen("","w",stdout);
int t=1;
// cin >>t;
for(int i=1;i<=t;i++){
// cout << "Case " << i << ":\n";
solve();
}
}
Compilation message
anagramistica.cpp: In function 'void solve()':
anagramistica.cpp:52:7: warning: unused variable 'ans' [-Wunused-variable]
52 | int ans=0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
11696 KB |
Output is correct |
2 |
Correct |
18 ms |
16460 KB |
Output is correct |
3 |
Correct |
19 ms |
19324 KB |
Output is correct |
4 |
Correct |
26 ms |
24516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
11 ms |
11696 KB |
Output is correct |
7 |
Correct |
18 ms |
16460 KB |
Output is correct |
8 |
Correct |
19 ms |
19324 KB |
Output is correct |
9 |
Correct |
26 ms |
24516 KB |
Output is correct |
10 |
Correct |
5 ms |
5836 KB |
Output is correct |
11 |
Correct |
4 ms |
4160 KB |
Output is correct |
12 |
Correct |
9 ms |
8652 KB |
Output is correct |
13 |
Correct |
8 ms |
8476 KB |
Output is correct |
14 |
Correct |
17 ms |
16180 KB |
Output is correct |
15 |
Correct |
17 ms |
15404 KB |
Output is correct |
16 |
Correct |
33 ms |
29252 KB |
Output is correct |
17 |
Correct |
29 ms |
23616 KB |
Output is correct |
18 |
Correct |
25 ms |
24268 KB |
Output is correct |