#include <bits/stdc++.h>
#define pb push_back
#define mod 1000000007
#define ll long long
#define int long long
using namespace std;
const int N = 10005;
string s[N];
vector <int> v;
int dp[N],d[N],P[N];
ll go(ll a,ll b){
ll ans =1;
while(b){
if (b&1) ans = (ans * a)%mod;
a = (a*a)%mod;
b/=2;
}
return ans;
}
ll C(int m,int n){
ll x = P[n],y = P[m],z = P[n - m];
y = (y*z)%mod;
return (x * go(y, mod - 2))%mod;;
}
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,k;
cin>>n>>k;
for (int i=1;i<=n;i++){
cin>>s[i];
sort(s[i].begin(),s[i].end());
}
P[0] = 1;
for (int i = 1; i <= 2000; i++)
P[i] = (P[i - 1]*i)%mod;
sort(s+1,s+n+1);
int cnt=1;
for (int i=1; i<=n; i++){
if (s[i] != s[i + 1]) v.pb(cnt),cnt=0;
cnt++;
}
ll ans=0;
dp[0] = 1;
for(int i=0; i <v.size();i++){
for (int m = 1; m <= v[i]; m++){
for (int j = 0; j <= 2000; j++){
ll x = (m*(m - 1))/2;
if (j + x > k) break;
d[j + x] = (dp[j]*C(m,v[i]) + d[j + x])%mod;
}
}
for (int j=0;j<=2000;j++)
dp[j] = (dp[j] + d[j])%mod,d[j]=0;
}
cout<<dp[k];
}
Compilation message
anagramistica.cpp:25:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main (){
| ^
anagramistica.cpp: In function 'int main()':
anagramistica.cpp:48:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i=0; i <v.size();i++){
| ~~^~~~~~~~~
anagramistica.cpp:46:8: warning: unused variable 'ans' [-Wunused-variable]
46 | ll ans=0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
3 ms |
716 KB |
Output is correct |
3 |
Correct |
2 ms |
652 KB |
Output is correct |
4 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
2 ms |
588 KB |
Output is correct |
7 |
Correct |
3 ms |
716 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
4 ms |
716 KB |
Output is correct |
10 |
Correct |
21 ms |
588 KB |
Output is correct |
11 |
Correct |
9 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
588 KB |
Output is correct |
13 |
Correct |
8 ms |
588 KB |
Output is correct |
14 |
Correct |
13 ms |
716 KB |
Output is correct |
15 |
Correct |
6 ms |
588 KB |
Output is correct |
16 |
Correct |
55 ms |
716 KB |
Output is correct |
17 |
Correct |
90 ms |
588 KB |
Output is correct |
18 |
Correct |
3 ms |
716 KB |
Output is correct |