This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |