Two sets of Rocks are different if one of them contains a Rock with a number that is not contained in the other set.
不同石头的定义:
只要有一个不同就是不同 。
注意 :不足k个的时候。
然后 注意 最后一个 颜色的时候可能有多个 用排列组合数求解。
A - Adventure Time
#include<bits/stdc++.h>
using namespace std;
# define maxn 30
# define inf 0x3f3f3f3f
int a[30]= {0};
long long combin(long long x,long long y)
{
long long q=1,p=1;
long long c=max(y-x,x);
long long d=min(y-x,x);
for(int i=c+1; i<=y; i++)
p*=i;
for(int j=1; j<=d; j++)
q*=j;
return p/q;
}
bool cmp(int x,int y)
{
return x>y;
}
string str;
int main()
{
long long k,temp,sum=0,cnt=0,ans=0,index=0;
cin>>str>>k;
for(int i=0; i<str.size(); i++)
{
temp=str[i]-'a';
a[temp]++;
}
sort(a,a+26,cmp);
for(int i=0; i<k; i++)
{
sum+=a[i];
if(a[i]==0)
{
k=i;
break;
}
}
for(int i=0; i<k; i++)
if(a[i]==a[k-1])
cnt++;
for(int i=0; i<26; i++)
if(a[i]==a[k-1])
index++;
ans=combin(cnt,index);
cout<<sum<<" "<<ans<<endl;
return 0;
}
540




被折叠的 条评论
为什么被折叠?



