dfs 第3题 没做出来

ykj12 2022-07-17 10:05:36 1
#include<bits/stdc++.h>
using namespace std;
int n,k,m;
const int N=25;
int a[N],vis[N];
int ans;
void dfs(int u,int sum){
	if(u==k+1){
		if(sum==m){
			ans++;
		}
		return;
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			vis[i]=1;
			dfs(u+1,sum+a[i]);
			vis[i]=0;
		}
	}
}
int main(){
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
	scanf("%d %d %d",&n,&k,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}
{{ vote && vote.total.up }}