JZ1186 【提高】背包问题00 题解

#include<bits/stdc++.h>
using namespace std;
int w,n,a[30],ans;
void dfs(int noww,int depth){
	if(noww==0){ans++;return;}
	if(noww<0 || depth>n) return;
	dfs(noww-a[depth],depth+1);
	dfs(noww,depth+1);
}
int main(){
	cin>>w>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	} 
	dfs(w,0);
	cout<<ans/2;
	return 0;
}
上一篇:leetcode 199.二叉树的


下一篇:[USACO 2019.12 Platinum]Tree Depth