80分求调(有关注)
查看原帖
80分求调(有关注)
1343286
Mincraft_Player楼主2025/1/4 20:18
#include<cstdio>
typedef long long ll;
ll n,m,r,ans,a[35],b[35];
void dfs(ll k,ll cnt,ll now){
	if(k>r){
		if(cnt<=m)ans++;
		return;
	}
	if(cnt>m)return;
	for(ll i=now+1;i<=n;i++)
		dfs(k+1,cnt+a[i],i);
}
ll fac(ll x){
	ll pro=1;
	for(ll i=2;i<=x;i++)
		pro*=i;
	return pro;
}
ll A(ll x,ll y){
	ll pro=1;
	for(ll i=x;i>x-y;i--)
		pro*=i;
	return pro;
}
ll C(ll x,ll y){
	return A(x,y)/fac(y);
}
int main(){
	scanf("%lld%lld%lld",&n,&r,&m);
	for(ll i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	dfs(1,0,0);
	printf("%lld\n",C(n,r)-ans);
	return 0;
}
2025/1/4 20:18
加载中...